javascript - vue 使用component 動(dòng)態(tài)組件為什么不成功
問(wèn)題描述
1.為什么使用component 動(dòng)態(tài)的添加組件沒(mé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是可以動(dòng)態(tài)的添加上的,為什么引入的modal 組件不行呢?
問(wèn)題解答
回答1:modal不是最開(kāi)始的組件嗎..是mounted時(shí)候無(wú)法加載modal.點(diǎn)了button之后反而可以加載first ?
還有一點(diǎn).data正確寫法是需要返回一個(gè)對(duì)象
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. 在mybatis使用mysql的ON DUPLICATE KEY UPDATE語(yǔ)法實(shí)現(xiàn)存在即更新應(yīng)該使用哪個(gè)標(biāo)簽?2. mysql - 表名稱前綴到底有啥用?3. Navicat for mysql 中以json格式儲(chǔ)存的數(shù)據(jù)存在大量反斜杠,如何去除?4. mysql - 數(shù)據(jù)庫(kù)表中,兩個(gè)表互為外鍵參考如何解決5. 哭遼 求大佬解答 控制器的join方法怎么轉(zhuǎn)模型方法6. mysql儲(chǔ)存json錯(cuò)誤7. mysql - 怎么生成這個(gè)sql表?8. 怎么php怎么通過(guò)數(shù)組顯示sql查詢結(jié)果呢,查詢結(jié)果有多條,如圖。9. sql語(yǔ)句 - 如何在mysql中批量添加用戶?10. 編輯成功不顯示彈窗
