From 74aabc2c292f4ee9ab73cf481ed2c7adc8cc3c76 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Tue, 09 Apr 2024 16:38:08 +0800 Subject: [PATCH] 公共工具,添加防抖和节流函数 --- layout/h5Page/CContent.vue | 41 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 40 insertions(+), 1 deletions(-) diff --git a/layout/h5Page/CContent.vue b/layout/h5Page/CContent.vue index 775f77c..dff8ecc 100644 --- a/layout/h5Page/CContent.vue +++ b/layout/h5Page/CContent.vue @@ -5,12 +5,51 @@ <template> <view class="c-content"> - <slot /> + <view + class="c-content-inner" + v-if="scroll==='off'" + > + <slot /> + </view> + <scroll-view + class="c-content-scroll" + v-if="scroll==='on'" + :scrollY="true" + :scroll-top="scrollTop" + :scroll-with-animation="true" + ref="scrollor" + @scroll="evt => handleScroll(evt)" + > + <slot /> + </scroll-view> </view> </template> <script> export default { name: 'CContent', + props: { + // 开启滚动,off / on + scroll: { + type: String, + default: 'off', + }, + }, + data() { + return { + scrollTop: '', + }; + }, + methods: { + handleScroll(evt) { + this.scrollTop = evt.target.scrollTop; + }, + $scrollTop(top) { + if (this.scroll === 'off') { + return; + } + this.scrollTop = top || 0; + }, + }, }; </script> \ No newline at end of file -- Gitblit v1.9.1