分析原因应该是点击切换标签页时,组件没有销毁。
解决办法:给组件添加 v-if
判断,使组件真正的创建和销毁。然后就在组件中定义的 mounted
和 destoryed
钩子函数就可以被正常调用了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <template> <div class="app-container"> <el-tabs v-model="activeName" @tab-click="handleClick" type="border-card"> <el-tab-pane name="realTimeState"> <span slot="label"> <i class="el-icon-time"></i> 实时状态</span> <realTimeState v-if="activeName === 'realTimeState'" /> </el-tab-pane> <el-tab-pane name="historyData"> <span slot="label"> <i class="el-icon-document"></i> 历史状态</span> <historyData v-if="activeName === 'historyData'" /> </el-tab-pane> <el-tab-pane name="basicInfo"> <span slot="label"> <i class="el-icon-info"></i> 基本信息</span> <basicInfo v-if="activeName === 'basicInfo'" /> </el-tab-pane> <el-tab-pane name="exportData"> <span slot="label"> <i class="el-icon-download"></i> 状态导出</span> <exportData v-if="activeName === 'exportData'" /> </el-tab-pane> <el-tab-pane name="error"> <span slot="label"> <i class="el-icon-error"></i> 故障查询</span> <error v-if="activeName === 'error'" /> </el-tab-pane> <el-tab-pane name="statusPicture"> <span slot="label"> <i class="el-icon-picture"></i> 预警监测</span> <statusPicture v-if="activeName === 'statusPicture'" /> </el-tab-pane> </el-tabs> </div> </template>
|
Reference
tabs + 组件使用会导致什么呢?