主要是將父組件里data中的數(shù)據(jù)通過在子組件里使用props屬性對數(shù)據(jù)進行傳遞,傳遞時應(yīng)注意組件標(biāo)簽里面通過 :xx='data里面的數(shù)據(jù)',放到組件標(biāo)簽上,然后將值通過props:['xx']將值放到組件內(nèi)部,這樣就可以在子組件里進行傳值
<body>
<div id="app">
<list-btn :tit='msg'></list-btn>
</div>
</body>
<script type="text/javascript">
Vue.component('list-btn',{
? ? ? ? ? ? ? ? props:['tit'],
? ? ? ? ? ? ? ? data:function(){
? ? ? ? ? ? ? ? ? ? ? ?return { count:0 }
? ? ? ? ? ? ? ? ? },
????????template:`<div> <p>我是{{tit}}</p> </div>`
})
let app=new Vue({
el:'#app',
data:{ msg:'我是father' },
methods:{}
})
</script>