window.history.pushState(null, null, '#')
window.addEventListener('popstate', function () {
window.history.pushState(null, null, '#')
})
mounted() { const that = this window.history.pushState(null, null, '#') window.addEventListener('popstate', function () { window.history.pushState(null, null, '#') that.fn() }) }, // 这里限制返回必须写在create声明周期或者mounted声明周期 that.fn()是一个方法,可以做返回拦截,比如封装一个弹窗,对用户返回操作进行提示
Vue代码块中还可以这样做,做拦截