component 標簽
Vue框架自定義的標簽,它的用途就是可以動態綁定我們的組件,根據數據的不同更換不同的組件。
例:
1、自定義3個組件
var cpA={
template:`<div>我是組件A</div>`
}
...
2、在構造器里掛載組件
components:{
"cpA":cpA
}
3、html里插入component標簽,並綁定who數據,根據who的值不同,調用不同的組件。
<component v-bind:is="who"></component>
<button @click="changeCp">更換組件</button>
methods:{
changeCp:function(){
if(this.who=="cpA"){
this.who="cpB"
}else if(this.who=="cpB"){
this.who="cpC"
}else{
this.who="cpA"
}
}
}
