js 原生js監聽物理返回鍵

原生JS 監聽物理返回鍵

1.在此使用的Vue寫的,

   mounted() {
        //監聽物理返回鍵
          if (window.history && window.history.pushState) {
            history.pushState(null, null, document.URL);
            window.addEventListener('popstate', this.fun, false);//false阻止默認事件
          }
    },
  methods: {
     /**
      * 監聽物理返回鍵執行的方法
      * */
       fun(){
         console.log("監聽到了")
        },
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章