父传子props驼峰标识
props中的变量如果有驼峰命名的情况:
在组件使用的时候就需要使用 -加上该大写字母的小写,即大写字母替换为-其小写字母
例如:
复制代码
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>组件的构建</title> </head> <!--组件是单独封装的模块,拥有自己的data html模块--> <!--组件中不可以访问vue实例中的data数据,不建议在里面访问vue实例对象--> <!--组件中data中的数据必须以方法函数的方式返回数据,好处是函数可以直接返回一个对象,每一次返回数据对象都不一样,这样可以让数据不受影响--> <body> <div id="app2"> <cpn v-bind:title-msg-title = "tmsg" :st="str"></cpn> <cpn v-bind:title-msg-title = "tmsg" :st="str" :t2 ='t2msg'></cpn> </div> <!--方法一写在script里面--> <script type="text/x-template" id="cpn"> <div> <!-- props传值如果遇到驼峰命名就需要-加上小写--> <h1>hhhhhhhhhh{{titleMsgTitle}}</h1> <h5>{{st}}</h5> <h5>{{t1}}</h5> <h5>{{t2}}</h5> </div> </script> <!--方法二直接使用template标签--> <script src="../vue.js"></script> <script> <!-- 创建组件构造对象--> const cpn=('#cpn',{template: `#cpn`, //做類型限制 //做默认数据 //是否传值限制 props:{ titleMsgTitle:Array, st:String, t1:{ type:String, default:'這個是默认数据没有填写的时候' // 数据类型为数组或者是对象的时候默认数据值需要为函数 }, t2:{ type:Array, default: function (){ return{ t2:'hello' } }, required:true } // 必须设置要给默认数据requierd }, data(){ return{ } }} ) let app=new Vue({ el:'#app2', data:{ str:'jiayou', tmsg:['kk','aa','ww'], stmsg:'hhh', t1msg: '' , t2msg:[11,22,334] }, components:{cpn} }) </script> </body> </html>
自己可以去对比一下我上一篇文章
然后这里使用驼峰命名的部分就是:titleMsgTitle
最后
以上就是无私老鼠最近收集整理的关于Vue使用props请注意父传子props驼峰标识的全部内容,更多相关Vue使用props请注意父传子props驼峰标识内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复