如果是页面切换不是tab拦切换的话,可以这样写:
<div
:class="['herd_item', { active: activeIndex === index }]"
v-for="(item, index) in headerList"
@click="handleTabToggle(index, item)"
:key="index"
>
{{ item.txt }}
</div>
<component :is="activeComponent"></component>
//数据
activeIndex: 0,
activeComponent: VRAR,
headerList: [
{ txt: "VR/AR测试", comp: VRAR },
{ txt: "运动控制", comp: MotionControl },
{ txt: "产线检测", comp: DetecTion },
{ txt: "帮助", comp: Assist },
],
// 处理tab切换
handleTabToggle(index, item) {
this.activeIndex = index;
this.activeComponent = item.comp;
},
就不用这种老办法了,用if套用判断
<!-- VRAR -->
<!-- <VRAR v-if="activeIndex == 0"></VRAR> -->
<!-- 运动控制 -->
<!-- <MotionControl v-if="activeIndex == 1"></MotionControl> -->
<!-- 产线检测-->
<!-- <DetecTion v-if="activeIndex == 2"></DetecTion> -->
<!-- 帮助 -->
<!-- <Assist v-if="activeIndex == 3"></Assist> -->