在home页面created钩子中监听popstate事件
created() { window.addEventListener("popstate",this.monitorBackForward,false) monitorBackForward(){ console.log(window.location.href.split("#")[1]) let path = window.location.href.split("#")[1] var menu getMenu(this.menuData) function getMenu(menuData){ for(let i=0;i< menuData.length;i++){ if(menuData[i].path == path){ menu = menuData[i] }else{ getMenu(menuData[i].childList) } } } console.log(menu) this.$store.commit("saveCurrentMenuBtns",menu.buttonList) this.$store.commit("addTab",menu) },
并在具体的页面中使用setTimeout延迟大概100ms,延迟的原因是,等着执行完获取必要的信息 如 menuBtnsArr
computed: { menuBtnsArr() { return this.$store.state.currentMenuBtns; }, langObj() { return this.$store.state.langFile; }, }, beforeMount() { setTimeout(() => { this.allBtnObj = this.$util.btnArrToObj(this.menuBtnsArr); console.log(this.allBtnObj) }, 100); this.screenHeight = document.documentElement.clientHeight || document.body.clientHeight; }, mounted() { setTimeout(() => { this.getAlarmTypeList(); this.getConfig(); this.getList(); this.getStatusList(); this.getAlarmStatusList(); }, 100); },
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有