如下所示:
复制代码
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<!DOCTYPE html> <html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.jsdelivr.net/npm/vue"></script> </head> <body> <div id="prop-example-2"> <input v-model="parentMsg"> <br> <child v-bind:my-message="parentMsg"></child> </div> <script> Vue.component('child',{ props:['myMessage'], template:'<span>{{ myMessage }}</span>' }) new Vue({ el:'#prop-example-2', data:{ parentMsg:'Messsssssssssssss' } }) </script> </body> </html>
这里需要注意的是在html中的 my-message 就是scrpit中的 myMessage。因为:
HTML 特性是不区分大小写的。所以,当使用的不是字符串模板时,camelCase (驼峰式命名) 的 prop 需要转换为相对应的 kebab-case (短横线分隔式命名)
以上这篇Vue 使用Props属性实现父子组件的动态传值详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持靠谱客。
最后
以上就是个性篮球最近收集整理的关于Vue 使用Props属性实现父子组件的动态传值详解的全部内容,更多相关Vue内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复