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.點了button之后反而可以加載first ?
還有一點.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’;
相關文章:
1. 對mysql某個字段監(jiān)控的功能2. showpassword里的this 是什么意思?代表哪個元素3. html - vue項目中用到了elementUI問題4. JavaScript事件5. python - 為什么正常輸出中文沒有亂碼,zip函數(shù)之后出現(xiàn)中文編程unicode編碼的問題,我是遍歷輸出的啊。6. python - 使用readlines()方法讀取文件內(nèi)容后,再用for循環(huán)遍歷文件與變量匹配時出現(xiàn)疑難?7. javascript - table列過多,有什么插件可以提供列排序和選擇顯示列的功能8. javascript - js中向下取整9. javascript - HTML字符串排版10. html5 - ElementUI table中el-table-column怎么設置百分比顯示。
