VUE种跳转页面后,阻止返回

VUE种跳转页面后,阻止返回

方法一、在跳转到的页面内加上下面的代码:

created() {
    
    
    history.pushState(null, null, document.URL);
    window.addEventListener("popstate", function () {
    
    
      history.pushState(null, null, document.URL);
    });
  },

方法二、注入插件
1)安装:

npm install vue-prevent-browser-back --save

2)在不允许返回的页面内导入:

import preventBack from 'vue-prevent-browser-back'

3)在不允许返回的页面内注入:

export default {
    
    
  mixins:[preventBack],  // 注入
  data() {
    
    
    return {
    
    ....};
  },
  .
  .
  .
}  

猜你喜欢

转载自blog.csdn.net/Kindergarten_Sir/article/details/109062595
今日推荐