vue學習筆記17 component 標簽


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"
    }
  }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM