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正確寫(xiě)法是需要返回一個(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的值寫(xiě)成modal,而不是’modal’;
相關(guān)文章:
1. javascript - 微信網(wǎng)頁(yè)開(kāi)發(fā)從菜單進(jìn)入頁(yè)面后,按返回鍵沒(méi)有關(guān)閉瀏覽器而是刷新當(dāng)前頁(yè)面,求解決?2. mysql replace 死鎖3. android - 安卓做前端,PHP做后臺(tái)服務(wù)器 有什么需要注意的?4. mysql - ubuntu開(kāi)啟3306端口失敗,有什么辦法可以解決?5. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?6. extra沒(méi)有加載出來(lái)7. python3.x - Python not 運(yùn)算符的問(wèn)題8. python - 數(shù)據(jù)與循環(huán)次數(shù)對(duì)應(yīng)不上9. mysql - C#連接數(shù)據(jù)庫(kù)時(shí)一直這一句出問(wèn)題int i = cmd.ExecuteNonQuery();10. python小白,關(guān)于函數(shù)問(wèn)題
