javascript - vue 使用component 動態(tài)組件為什么不成功
問題描述
1.為什么使用component 動態(tài)的添加組件沒有成功,
<template>
<component @showHide='recieveAddData' :is='addModal' ></component> <button @click='switchComponent'></button>
</template>import modal from ’./company/modal.vue’export default {
name: ’addItem’,data () { addModal: ’modal’},methods: { switchComponent () { this.addModal = ’first’},components: { modal, first: { template: '<p>這里是子組件3</p>' }}
}
為什么組件first是可以動態(tài)的添加上的,為什么引入的modal 組件不行呢?
問題解答
回答1:modal不是最開始的組件嗎..是mounted時候無法加載modal.點(diǎn)了button之后反而可以加載first ?
還有一點(diǎn).data正確寫法是需要返回一個對象
data() { return {}}回答2:
import modal from ’./company/modal.vue’;export default {name: ’addItem’,methods: { switchComponent () { this.addModal = ’first’},computed:{ addmodal:modal },components: { first: { template: '<p>這里是子組件3</p>' }}}
你在components中的modal去掉,addModal的值寫成modal,而不是’modal’;
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””2. boot2docker無法啟動3. docker-compose中volumes的問題4. java - SSH框架中寫分頁時service層中不能注入分頁類5. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.6. nignx - docker內(nèi)nginx 80端口被占用7. dockerfile - 為什么docker容器啟動不了?8. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?9. docker容器呢SSH為什么連不通呢?10. 關(guān)于docker下的nginx壓力測試

網(wǎng)公網(wǎng)安備