javascript - vue 使用component 动态组件为什么不成功
问题描述
1.为什么使用component 动态的添加组件没有成功,
<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是可以动态的添加上的,为什么引入的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. angular.js - 如何控制ngrepeat输出的个数2. 网页爬虫 - python requests爬虫,如何post payload3. node.js - 问个问题 Uncaught (in promise)4. python爬虫 - scrapy使用redis的时候,redis需要进行一些设置吗?5. mysql5.7就没有官方性质的详细配置文件吗?求大神告知6. angular.js - angular指令中的scope属性中用&获取父作用域函数的问题7. CSS3 flex 如何让高度不等的同排等高?8. python3.x - python3.5.2安装时make报错求助9. python 读取csv文件可以读取但内容错误,但单独用excel打开正常,如何解决?10. 用CSS3 box-sizing 属性实现两个并排的容器,如果想让容器中间有间隔该如何实现

网公网安备