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時(shí)候無法加載modal.點(diǎn)了button之后反而可以加載first ?
還有一點(diǎn).data正確寫法是需要返回一個(gè)對象
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. javascript - immutable配合react提升性能?2. javascript - sublime快鍵鍵問題3. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問?4. javascript - 移動端上不能實(shí)現(xiàn)拖拽布局嗎?5. css - 寫頁面遇到個(gè)布局問題,求大佬們幫解答,在線等,急!~6. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化7. 配置Apache時(shí),添加對PHP的支持時(shí)語法錯(cuò)誤8. 實(shí)現(xiàn)bing搜索工具urlAPI提交9. phpstudy8.1支持win11系統(tǒng)嗎?10. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問

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