监听浏览器返回

监听浏览器返回

mounted() {
    
    
  if (window.history && window.history.pushState) {
    
    
    history.pushState(null, null, document.URL); //这里有没有都无所谓,最好是有以防万一
    window.addEventListener("popstate", this.goBack, false); // 回退时执行goback方法
  }
},
methods:{
    
    
  goBack() {
    
    
      this.$router.push({
    
     name: 'floor', params: {
    
     BName: this.header.buildName})
       // 接收参数用this.$route.params.BName
    },
}

猜你喜欢

转载自blog.csdn.net/weixin_43045869/article/details/126681583