例-2020-0520-vue滚动跳转
vue获取:
<div class="container" :class='{forNorecode:couponList.length===0}' ref="wrapper">
</div>
//获取高度
let wrapperScrollTop = this.$refs.wrapper.scrollTop
console.log('leave1---', wrapperScrollTop)
//滚动
setTimeout(() => {
console.log('定时器')
this.$refs.wrapper.scrollTop = 1007
}, 1000)
原生获取高度:
let containerId = document.getElementById('containerId')
console.log('leave3---', containerId.scrollTop)
beforeRouteLeave(to, from, next) {
let wrapperScrollTop = this.$refs.wrapper.scrollTop
console.log('leave1---', wrapperScrollTop)
// let app = document.getElementById('app')
// console.log('leave2---', app.scrollTop)
//--
// let tabContentId = document.getElementById('tabContentId')
// console.log('leave2---', tabContentId.scrollTop)
let containerId = document.getElementById('containerId')
console.log('leave3---', containerId.scrollTop)
next()
},
beforeRouteLeave(to, from, next) {
let wrapperScrollTop = this.$refs.wrapperMy.scrollTop
console.log('leave_wrapperMy---', wrapperScrollTop)
//----
let app = document.getElementById('app')
let containerId = document.getElementById('containerId')
// console.log('leave2---', app.scrollTop)
// console.log('leave2---', tabContentId.scrollTop)
console.log('leave3---', containerId.scrollTop)
next()
},
this.timer = setTimeout(() => {
this.$refs.containerMyRef.scrollTop = this.scrollTop
}, 500)
//清除定时器
beforeRouteLeave(to, from, next) {
let wrapperScrollTop = this.$refs.containerMyRef.scrollTop
// console.log('containerMyRef---', wrapperScrollTop)
this.setScrollTop(wrapperScrollTop)
this.timer && clearTimeout(this.timer)
next()
},