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. windows误人子弟啊2. 冒昧问一下,我这php代码哪里出错了???3. MySQL主键冲突时的更新操作和替换操作在功能上有什么差别(如图)4. python - linux怎么在每天的凌晨2点执行一次这个log.py文件5. 数据库 - Mysql的存储过程真的是个坑!求助下面的存储过程哪里错啦,实在是找不到哪里的问题了。6. 实现bing搜索工具urlAPI提交7. mysql优化 - MySQL如何为配置表建立索引?8. 如何用笔记本上的apache做微信开发的服务器9. 我在网址中输入localhost/abc.php显示的是not found是为什么呢?10. 关于mysql联合查询一对多的显示结果问题
