记录一次scroll-view组件设置scroll-top 0 无效

uniappscroll-top组件滚动问题及官方解决方案
文章讨论了在uniapp中使用scroll-top组件时遇到的问题,即设置scroll-top为0无法多次生效。官方解释了原因并提供了监听scroll事件记录滚动位置的解决方案。

在使用uniapp的scroll-top组件时,滚动到底部切换其他类型时,设置scroll-top为0,发现只有第一次切换能够成功回到顶部, 之后每次切换设置的scroll-top 没有效果。

官方说法是:
当重复设置某些属性为相同的值时,不会同步到view层。 例如:每次将scroll-view组件的scroll-top属性值设置为0,只有第一次能顺利返回顶部。 这和props的单向数据流特性有关,组件内部scroll-top的实际值改动后,其绑定的属性并不会一同变化。

对此,官方也给出了解决方案:
监听scroll事件,记录组件内部变化的值,在设置新值之前先设置为记录的当前值

<scroll-view scroll-y="true" :scroll-top="scrollTop" @scroll="scroll"></scroll-view>
export default {
    data() {
        return {
            scrollTop: 0,
            old: {
                scrollTop: 0
            }
        }
    },
    methods: {
    	// 滚动时,记录一下滚动位置
        scroll: function(e) {
            this.old.scrollTop = e.detail.scrollTop
        },
        // 先把滚动位置赋值给scroll-top,再把scroll-top的值设置为0
        goTop: function(e) {
            this.scrollTop = this.old.scrollTop
            this.$nextTick(function() {
                this.scrollTop = 0
            });
        }
    }
}

官方还提供了另一种方法,但是还需要自己特别处理,因此不做推荐,感兴趣的可以看下官网说法

The TPS54331 is a 28-V, 3-A non-synchronous buck Integrated 80 mΩ High Side MOSFET Supports up to 3A Continuous Output Current converter that integrates a low Rds(on) high side MOSFET. To increase efficiency at light loads, a pulse skipping Eco-mode™ feature is automatically High Efficiency at Light Loads with a Pulse activated. Furthermore, the 1 A shutdown supply Skipping Eco-mode™ current allows the device to be used in battery Fixed 570kHz Switching Frequency Typical 1A Shutdown Quiescent Current powered applications. Current mode control with internal slope compensation simplifies the external compensation calculations and reduces component Adjustable Slow Start Limits Inrush Currents count while allowing the use of ceramic output Programmable UVLO Threshold Overvoltage Transient Protection capacitors. A resistor divider programs the hysterisis of the input under-voltage lockout. An overvoltage transient protection circuit limits voltage overshoots Cycle by Cycle Current Limit, Frequency Fold during startup and transient conditions. A cycle by Back and Thermal Shutdown Protection cycle current limit scheme, frequency fold back and Available in Easy-to-Use SOIC8 Package Supported by SwitcherPro™ Software Tool (http://focus.ti.com/docs/toolsw/folders/print/s witcherpro.html) For SWIFT™ Documentation, See the TI Website at www.ti.com/swift thermal shutdown protect the device and the load in the event of an overload condition. The TPS54331 is available in an 8-pin SOIC package that has been internally optimized to improve thermal performance.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值