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);
}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐