美文网首页
vue监听浏览器后退

vue监听浏览器后退

作者: 肆意放纵 | 来源:发表于2019-08-12 15:00 被阅读0次

首先

 mounted(){
   if (window.history && window.history.pushState) {
        history.pushState(null, null, document.URL);
        window.addEventListener('popstate', this.cancel, false);
   }
 },

然后

 cancel() {
     this.$router.push({
          name:"orderList",
          query: {
              pageSize: this.$route.query.pageSize,
              status: this.$route.query.status,
          }
      });
  },

最后销毁

destroyed(){
    window.removeEventListener('popstate', this.cancel, false);
}

相关文章

网友评论

      本文标题:vue监听浏览器后退

      本文链接:https://www.haomeiwen.com/subject/ehdujctx.html