//页面跳转前 判断需要从哪些页面跳转过来需要刷新的页面
router.beforeEach((to, from, next) => {
next();
setTimeout(()=>{
if((from.name==‘index‘||from.name==‘link‘)&&!vm.pop&&to.name==‘serve‘){
router.go(0);
}
},500)
});
new.vue
这里使用的是#id 的方式跳转
mounted() {
var hash = window.location.hash;
//获取到id
var index = hash.lastIndexOf("#");
if (index != -1) {
var id = hash.substring(index + 1, hash.length + 1);
var div = document.getElementById(id);
if (div) {
//这个方法在页面刷新的时候可以跳到对应锚点
div.scrollIntoView();
}
}
}
以上处理相对来说比较简单