如何做到點擊一個按鈕動態添加一個組件呢?是.vue組件
vue2.0動態添加組件
哈士奇WWW
2018-09-11 13:30:00
TA貢獻1815條經驗 獲得超13個贊
我是寫在父組件中的:
Vue.component('mycontent', { props: ['content'], data() { return { coms: [], } }, render: function(h) { this.coms = []; for(var i = 0; i < this.content.length; i++) { this.coms.push(h(this.content[i], {})) } return h('div', {}, this.coms) }, });
調用的時候
<mycontent v-bind:content="content"></mycontent>
那么父組件中的content變化時,就會動態加載組件了
舉報