H5 监听手机返回事件

1.使用popstate监听返回事件

//在mounted  里面挂载 popstate  事件
mounted(){
   if (window.history && window.history.pushState) {
            history.pushState(null, null, '#1');
            window.addEventListener('popstate', this.backChange, false);
       }
},
  backChange(e){
         history.pushState(null, null, '#1');
         this.isShow=true;  //逻辑
    },
  destroyed(){
       window.removeEventListener('popstate', this.backChange, false);
},

你可能感兴趣的:(前端,javascript,事件)