component 使用
component的注冊(cè)
1.全局注冊(cè)
使用用Vue.component('componentName',{template:'<div class="tem1">hello world</div>'})在初始化實(shí)例之前。
componentName自定義名稱
在實(shí)例聲明的作用域下中使用<componentName></componentName> 成功渲染效果就是 '<div class="tem1">hello world</div>
Vue.component('my-component',{       template:'<div class="tem1">hello world</div>'     }  組件中的數(shù)據(jù)使用
component不能使用實(shí)例的data ,但是可以在component 使用data 聲明變量,data的使用只能使用函數(shù)形式
Vue.component('my-component',{       template:'<div class="tem1">hello world {{comdata}}</div>',       data:function(){return {comdata:'hehe'}}     });2.局部主持
在實(shí)例化的new Vue 中設(shè)置components
var app=new Vue({       el:'#app',       components:{'example':{template:'<div>children template</div>'}}     }) 組件中的數(shù)據(jù)使用
var app=new Vue({       el:'#app',       data:{num:220},       components:{         'example':{           template:'<div>children template{{mydata}}</div>',           data:function(){return {mydata:' mydata=data'};}         }        }     })注意:組件不能使用實(shí)例的data:{num:220}的參數(shù)會(huì)報(bào)錯(cuò)
組件中同樣支持methods、computed等其他屬性 不會(huì)沖突保持相對(duì)的獨(dú)立
這時(shí)候就必須考慮不同組件的數(shù)據(jù)通信問題
vue js總結(jié)來說通過props down events up 來傳輸數(shù)據(jù)
給父級(jí)調(diào)用數(shù)據(jù)使用props聲明,給子集調(diào)用使用events來聲明
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。
新聞熱點(diǎn)
疑難解答