Vue之组件分离写法
完整代码:
复制代码
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<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="../js/vue.js"></script> <title>component03</title> </head> <body> <div id="app"> <cpn1></cpn1> <cpn2></cpn2> </div> <!--分离写法1--> <script type="text/x-template" id="mycpn1"> <div> <h1>我是方式1模板</h1> </div> </script> <!--分离写法2--> <template id="mycpn2"> <div> <h2>我是方式2模板</h2> </div> </template> <script> Vue.component("cpn1", { template: "#mycpn1" }) Vue.component("cpn2", { template: "#mycpn2" }) new Vue({ el: "#app" }) </script> </body> </html>
发现:
复制代码
1
2
3
4
5`<div id="app"> <cpn1></cpn1> <cpn2></cpn2> </div>`
复制代码
1
2**这个”<div></div>“写在后面运行不成功。**弹出警告:
分离开后代码显得清晰多了。
最后
以上就是凶狠手机最近收集整理的关于Vue之组件分离写法(022)的全部内容,更多相关Vue之组件分离写法(022)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复