let getRandomCode = function(){
let d = new Date();
return d.getTime();
}
this.$router.push({path:'xxxxx',query:{randomCode: getRandomCode()}});
然后去路由对应的页面监听里写代码
'$route': { // $route可以用引号,也可以不用引号 监听的对象
handler(to, from){
if(to.fullPath!=from.fullPath){
if(this.$route.query.randomCode){
this.dataContent1.scrollIntoView({ block: "start", behavior: "smooth" });
}
}
},
// deep: true, // 深度观察监听 设置为 true
// immediate: true, // 第一次初始化渲染就可以监听到
},
mounted(){
this.dataContent1 = this.$el.querySelector(".data-content1");
}
.data-content1是你要调整定位的容器盒子上的class