在公共方法文件common.js中實現一個存儲當前歷史記錄的方法
common.js
// 存儲當前歷史記錄點,實現控制手機物理返回鍵的按鈕事件 var pushHistory = function () { let state = { title: '', url: '' } window.history.pushState(state, state.title, state.url) }
vue頁面
mounted () { pushHistory() // 監聽歷史記錄點, 添加返回事件監聽 window.onpopstate = () => { // 輸入要返回的上一級路由地址 this.$router.push({name: 'OrdersList'}) } },
這個在android中沒有問題,但是在蘋果手機中的safari瀏覽不行。。。
先留個坑,以后再研究,折騰了半天,沒有找到原因。
https://www.jianshu.com/p/18184bb699f5
https://blog.csdn.net/qq_40650146/article/details/85236411