国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

javascript - vue 使用component 動(dòng)態(tài)組件為什么不成功

瀏覽:132日期:2022-12-01 14:25:30

問題描述

1.為什么使用component 動(dòng)態(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是可以動(dòng)態(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’;

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 谢通门县| 拉萨市| 加查县| 若尔盖县| 进贤县| 丹棱县| 武城县| 三亚市| 漳州市| 陈巴尔虎旗| 大安市| 塔河县| 龙里县| 昌吉市| 象山县| 鸡泽县| 类乌齐县| 安徽省| 凌源市| 沙河市| 和顺县| 古浪县| 长岛县| 宁阳县| 柞水县| 寿光市| 临猗县| 左权县| 玛多县| 长汀县| 青浦区| 石屏县| 通城县| 镇远县| 三原县| 道孚县| 友谊县| 永泰县| 界首市| 沽源县| 谷城县|