模板分离开来,看起来不乱
1.模板分离写法1 ,script标签,类型必须是text/x-template
2.模板分离写法2 ,推荐,使用template标签
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title-hellovuejs</title> </head> <body> <div id ="app"> <!-- 3.使用组件 --> <my_cpn1></my_cpn1> <my_cpn2></my_cpn2> </div> <!-- 1.模板分离写法1 ,script标签,类型必须是text/x-template--> <script type="text/x-template" id="cpn1"> <div> <h2>我是标题</h2> <p>这是内容,模板分离写法1,script标签</p> </div> </script> <!-- 2.模板分离写法2 ,推荐,使用template标签--> <template id="cpn2"> <div> <h2>我是标题2</h2> <p>这是内容,模板分离写法2,使用template标签</p> </div> </template> <script src="../js/vue.js"></script> <script> //1.通过语法糖创建全局组件,模板分离写法1 //注意,使用了tab键上面的反斜杠``,因而可以换行定义 Vue.component('my_cpn1',{ template: '#cpn1' }); //root组件 const chen1 = new Vue({ el: '#app', //用于挂载要管理的元素 data:{//定义数据 message:'你好啊,helloword', isShow: true }, //2 以下语法糖形式直接创建是局部组件的用法 components:{ my_cpn2: { template:'#cpn2' } } }) </script> </body>
最后
以上就是含蓄万宝路最近收集整理的关于19vue学习_组件的模板分离写法的全部内容,更多相关19vue学习_组件内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复