mounted 生命周期中
// 清空回退的历史纪录
history.pushState(null, null, document.URL);
// 监听 前进或者后退
window.addEventListener('popstate', this.onPopstateFn)
beforeDestroy 生命周期中
// 清除监听
window.removeEventListener('popstate', this.onPopstateFn);
methods方法中
// 处理 浏览器后退
async onPopstateFn() {
if (history.pushState) {
// 对接口进行错误处理
try {
await this.stopWbPushStreamFn();
} catch (error) {
console.log('发送接口失败');
}
// 发送完接口 后 手动控制 前往的页面
this.$router.push("/teacher");
}
},