import { mapState, mapActions } from 'vuex' export default { data() { return { } }, beforeRouteEnter(to, from, next) { next((vm) => { if(['startProcess', 'approvalForm'].includes(from.name)) { // 从详情页回来,需要读取缓存中的 tabActive 默认选中进入详情页前选中的 tab vm.active = vm.tabActiveMap.get(vm.$route.name) } vm.init() }) }, beforeRouteLeave(to, from, next) { if(['startProcess', 'approvalForm'].includes(to.name)) { this.setTabActiveMemory(this.active) } next() }, methods: { ...mapActions('tabActive', ['setTabActive']), setTabActiveMemory(activeIndex) { this.setTabActive({tabName: this.$route.name, activeIndex}) } }, computed: { ...mapState('tabActive', ['tabActiveMap']) }, }