Vue动态组件 v-once指令

方法一
<component :is="type"></component> <button @click="change">change</button>

  

 

方法二

<child-one v-if="type==='child-one'"></child-one>
<child-two v-if="type==='child-two'"></child-two>
<button @click="change">change</button>

 

Vue.component("child-one",{
                
                template:`<div v-once>child-one</div>`,
            })
            
Vue.component("child-two",{
                
                template:`<div v-once>child-two</div>`,
            })
            //v-once把组件放到缓存里提高工作效率


var app =new Vue({

el:"#app",

data:{
type:'child-one'
},
methods:{
change:function(){

this.type = (this.type==='child-one' ? 'child-two':'child-one'),


}
}

})

 

posted @ 2019-04-15 22:32  我就是要叫鱼摆摆  阅读(325)  评论(0编辑  收藏  举报