<div>
<div>
<div class="content">
<div style="z-index: 999">
<div :class="['left', inAnimation ? 'Animationleft' : '']" ref="left">
<component :is="currentLeft"></component>
</div>
</div>
</div>
</div>
</div>
<script>
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import eventBus from '@/utils/vueBus'
@Component({
components: {},
})
export default class Pagecontent extends Vue {
navInfo = {}
inAnimation = false
id = 0
componentleft = [
{ name: 'firstPage', component: 'indexLeft' },
{ name: 'govern', component: 'governLeft' },
{ name: 'serve', component: 'serveLeft' },
{ name: 'health', component: 'healthLeft' },
{ name: 'education', component: 'educationLeft' },
{ name: 'LC', component: 'lcLeft' },
{ name: 'traffic', component: 'trafficLeft' },
{ name: 'neighbours', component: 'neighboursLeft' },
{ name: 'business', component: 'businessLeft' },
{ name: 'architect', component: 'architectLeft' },
]
activated() {}
@Watch('navInfo')
onChangeValue(newVal, oldVal) {
this.inAnimation = false
setTimeout(() => {
this.inAnimation = true
}, 200)
}
get currentLeft() {
Vue.component(
this.componentleft[this.id - 1] &&
this.componentleft[this.id - 1].component,
() =>
import(
`@/components/scene/${this.componentleft[this.id - 1].name}/${
this.componentleft[this.id - 1].component
}.vue`
)
)
return this.componentleft[this.id - 1].component
}
async created() {
this.inAnimation = false
setTimeout(() => {
this.inAnimation = true
}, 200)
//底部导航穿过来的参数
eventBus.$on('navValue', (data) => {
this.navInfo = data
this.id = data.id
})
}
}
</script>
按需加载子组件
最新推荐文章于 2022-11-05 22:23:14 发布
这个博客内容展示了如何在Vue应用中实现组件的动态加载,通过监听`navInfo`的变化来更新左侧栏的组件。在`activated()`钩子中处理页面激活状态,并在`watch`中平滑切换组件的动画效果。同时,利用事件总线(eventBus)接收底部导航传来的参数,实现实时更新组件内容。整个过程涉及Vue组件、状态管理和动态导入。
摘要由CSDN通过智能技术生成