javascript - Why does vue fail to use component dynamic components?
仅有的幸福
仅有的幸福 2017-05-31 10:39:56
0
2
752

1. Why using component to dynamically add components failed?

<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>"  
  }
}

}

Why can the first component be added dynamically, but why can’t the introduced modal component work?

仅有的幸福
仅有的幸福

reply all(2)
PHPzhong

Isn’t modal the first component?
The modal cannot be loaded when mounted.
After clicking the button, the first component can be loaded instead?

One more thing.
The correct way to write data is to return an object

data() {
    return {}
}
黄舟
import modal from './company/modal.vue';
export default {

name: 'addItem',
methods: {
  switchComponent () {
   this.addModal = 'first'
},
computed:{
    addmodal:modal 
},
components: {
  first: {
     template: "<p>这里是子组件3</p>"  
  }
}
}

Remove the modal in components and write the value of addModal as modal instead of 'modal';

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!