我是将scroll-view包装成了一个组件然后在,别的页面中调用,因为要实现一个回到顶部的功能,看了文档,试了好多次,scrll-top值都不生效,也百度谷歌了,
goTop: function(e) {
this.scrollTop = this.old.scrollTop
this.$nextTick(function() {
this.scrollTop = 0
});
uni.showToast({
icon:"none",
title:"纵向滚动 scrollTop 值已被修改为 0"
})
}
this.scollTop是要先等于this.old.scrollTop
就被这一步给少了
上面的代码也试过了,意思就是说两次scrll-top值一样,所以不渲染.要先设成不一样的,在为0.试过无效.
附上我的代码.
<template>
<view>
<cu-custom bgColor="bg-gradual-theme" :isBack="true">
<block slot="backText">返回</block>
<block slot="content">{{ title }}</block>
</cu-custom>
<scroll-view scroll-y="true" class="scroll" :style="top" @scrolltolower="lower" :scroll-top="scrollTop" @scroll="scroll"><slot></slot></scroll-view>
</view>
</template>
<script>
export default {
props: {
title: {
type: String,
default: '',
scrollTop: -1,
oldScrollTop: -1
}
},
data() {
return {
CustomBar: this.CustomBar
};
},
computed: {
top() {
return `top:${this.CustomBar}px`;
}
},
onLoad() {},
methods: {
lower: function(e) {
this.$emit('lower');
},
goTop() {
// this.scrollTop = this.oldScrollTop
this.$nextTick(()=>{
this.scrollTop = 0;
console.log(this.scrollTop)
});
// this.scrollTop = -1
},
scroll(e) {
this.scrollTop = e.detail.scrollTop;
// console.log(this.scrollTop)
// console.log(this.oldScrollTop)
}
}
};
</script>
<style lang="scss" scoped>
.scroll {
position: fixed;
bottom: 0;
}
</style>
goTop函数在页面中通过this.$refs形式调用
方龙 (作者)
没有,不解决了
2020-05-25 16:23
方龙 (作者)
需求砍掉 ,哈哈哈
2020-05-25 16:23
1***@qq.com
请参考:https://ask.dcloud.net.cn/article/36612
2020-09-07 15:28