vue动态组件is
在一个多标签的界面中使用 is
attribute 来切换不同的组件compOne.vue
<template>
<div>组件1</div>
</template>
compTwo.vue
<template>
<div>组件2</div>
</template>
exchange.vue
<template>
<div>
<el-button @click.native="changeComponent">切换</el-button>
<component :is="currentTabComponent"></component>
</div>
</template>
<script>
import compOne from './compOne'
import compTwo from './compTwo'
export default {
name: 'exchange',
data() {
return {
currentTabComponent: 'compOne'
}
},
components: {
compOne,
compTwo,
},
methods: {
changeComponent() {
if (this.currentTabComponent === 'compOne') {
this.currentTabComponent = 'compTwo'
} else {
this.currentTabComponent = 'compOne'
}
}
}
}
</script>
还没有评论,来说两句吧...