Vue---组件 初步

来源:互联网 发布:行知职校 编辑:程序博客网 时间:2024/05/22 17:00
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script src="js/vue.js"></script></head><body>        <div id="app">            <my-comp></my-comp>        </div>        <div id="app2">            <my-comp></my-comp>            <my-comp2></my-comp2>            <my-comp3></my-comp3>        </div></body><script>    /**     *     * 组件的命名规则:     *      1、组件的名称应该使用驼峰法(xxxXxxXxx)     *      2、或者中划线法(xxx-xx-xx),符合W3C规定的     *      3、尽量的命名规范,命名要有意义     *      4、不要使用html原有的标签名称(例如:a、span)     *     * */        Vue.component("myComp",{        template:"<h1>我是全局</h1>"    });    new Vue({        el:"#app",    });    var jub=new Vue({        components:{            myComp2:{                template:"<h1>我是局部2</h1>"            },            myComp3:{                template:"<s>我是局部3</s>"            }        }    }).$mount("#app2");//  }).$mount("#app");//相当于el : "#app"    new Vue({        el:"#app2",    })</script></html>
原创粉丝点击