<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of page</title>
</head>
<body>
<div id="example">
<input v-model="parentsg">
<br>
<child v-bind:parentsg="parentsg"></child>
<!-- 直接绑定根数据text ,但是必须指明根数据的路径shou.text-->
<todo-item v-bind:text="shou.text"></todo-item>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script >
// 注册
Vue.component(‘child‘, {
props: [‘parentsg‘],
template: ‘<span>{{ parentsg}}</span>‘
})
Vue.component(‘todo-item‘, {
props: [‘text‘],
template: ‘<p>{{text}}</p>‘
})
// 创建根实例
new Vue({
el: ‘#example‘,
data:{
parentsg:‘‘,
todo: {
text: ‘Learn Vue‘,
isComplete: false
},
shou: {
text: ‘shi wo ma‘,
isComplete: false
}
}
})
</script>
</html>
原文地址:https://www.cnblogs.com/dianzan/p/8504162.html