<component :is="componentName"></component>
import Page1 from './Page1'
import Page2 from './Page2'
import Page3 from './Page3'
export default [
Page1,
Page2,
Page3
]
<template>
<div>
<el-button @click="changePage(0)">页面1</el-button>
<el-button @click="changePage(1)">页面2</el-button>
<el-button @click="changePage(2)">页面3</el-button>
<component :is="componentPage[idx]"></component>
</div>
</template>
<script>
import componentPage from './index'
export default {
name: 'test',
data() {
return {
componentPage,
idx: 0
}
},
methods: {
changePage(idx) {
this.idx = idx
}
}
}
</script>