vue 页面跳组件,实现点击浏览器自带返回箭头,返回到上一个页面,而不是返回道上个路由

//这个方法是点击 点击添加跳转到添加页面
handleAdd(val) { let _that=this; let callback = function() { _that.isAdd=false window.removeEventListener("popstate", callback); }; history.pushState(null, null, "/more/basicInfo/HosData#detail"); window.addEventListener( "popstate",callback); this.isAdd = true; },

removeEventListener() 方法用于移除由 addEventListener() 方法添加的事件句柄

popstate浏览器返回事件

当活动历史记录条目更改时,将触发popstate事件。如果被激活的历史记录条目是通过对history.pushState()的调用创建的,或者受到对history.replaceState()的调用的影响,popstate事件的state属性包含历史条目的状态对象的副本。

需要注意的是调用history.pushState()或history.replaceState()不会触发popstate事件。只有在做出浏览器动作时,才会触发该事件,如用户点击浏览器的回退按钮(或者在Javascript代码中调用history.back())

猜你喜欢

转载自www.cnblogs.com/lvlvlv/p/11543909.html