注意:本人用的是vue语言
话不多说,直接上代码:
watch: {
$route(to, from) {
if (to.name == "callRecord" || "call") {
this.$store.commit("scrollHeight", this.scrollTop);
}
if (from.name == "callRecord" || "call") {
this.$refs.callCon.scrollTop = this.$store.state.scrollT;
}
},
},
在watch里面进行监听路由跳转情况, 我做的是跳转到组件名为callRecord或者call的页面的时候,记录跳转前页面滚动到位置. 然后,从callRecord或者call的页面返回过来的时候,将跳转到跳转之前的位置.