Vue 监听浏览器回退按钮
mounted() {if (window.history && window.history.pushState) {history.pushState(null, null, document.URL); //这里有没有都无所谓,最好是有以防万一window.addEventListener("popstate", this.goBack, false); // 回退时执行go
·
mounted() {
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL); //这里有没有都无所谓,最好是有以防万一
window.addEventListener("popstate", this.goBack, false); // 回退时执行goback方法
}
},
methods: {
tabEvent(id) {
this.curTabId = id;
this.$router.push({
path: `/group/view/${this.$route.params.id}`,
query: {
tabId: id
}
});
history.pushState(null, null, document.URL);
},
goBack() {
this.$router.replace({ path: "/groups" }); //根据其需求,回退到指定地址
}
},
destroyed() {
window.removeEventListener("popstate", this.goBack, false);
}
更多推荐
已为社区贡献10条内容
所有评论(0)