uniapp 操作 scroll-view 切换滚动条不返回顶端

 需求:每次切换 分类 的时候 将 scroll-view的滚动条返回到最上方

        我们在给 scroll-view 绑定了 scroll-top 属性后,通过事件处理函数 将scroll进行赋值,来达到每次切换可以返回顶部

        但是并不生效,因为每次赋值为相同的值并不生效!

<template>
    <scroll-view 
        class="right-scroll-view" 
        :scroll-top="scrollTop" 
        scroll-y 
        :style="{height:wh+'px'}">
    </scroll-view>
<template>

<script>
export default {
    data(){
        // 距离参数
        scrollTop:0
    },
    // 切换页面事件
	activeChanged(i) {
		this.scrollTop = 0
	},
}
</script>

正确写法:

        每次赋值的时候赋值不同的数据 就可以解决这个问题了

activeChanged(i) {
	this.scrollTop = this.scrollTop === 0 ? 1 : 0
},

猜你喜欢

转载自blog.csdn.net/Kerwin__li/article/details/128671774