File tree Expand file tree Collapse file tree
packages/uni-mp-vue/src/dom Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,12 +56,14 @@ function createUniElement(
5656 tagName
5757 )
5858 uniElement . $vm = ins . proxy
59- // 目前只有微信小程序支持获取 ScrollViewContext
60- if (
61- ( ins . proxy as ComponentPublicInstance & { $mpPlatform : string } )
62- . $mpPlatform === 'mp-weixin'
63- ) {
59+ const mpPlatform = (
60+ ins . proxy as ComponentPublicInstance & { $mpPlatform : string }
61+ ) . $mpPlatform
62+ if ( mpPlatform === 'mp-weixin' ) {
6463 initMiniProgramNode ( uniElement , ins )
64+ } else if ( mpPlatform === 'mp-alipay' ) {
65+ // 支付宝小程序不支持获取 ScrollViewContext,仅设置 scroll offset 相关属性
66+ syncUniElementScrollOffset ( uniElement )
6567 }
6668 uniElement . $onStyleChange ( ( styles ) => {
6769 let cssText = ''
@@ -200,6 +202,18 @@ function initMiniProgramNode(
200202 }
201203}
202204
205+ function syncUniElementScrollOffset ( uniElement : UniElement ) {
206+ if ( uniElement . tagName === 'SCROLL-VIEW' ) {
207+ uni
208+ . createSelectorQuery ( )
209+ . select ( '#' + uniElement . id )
210+ . fields ( { scrollOffset : true } , ( res : Record < string , any > ) => {
211+ setUniElementScrollOffset ( uniElement , res )
212+ } )
213+ . exec ( )
214+ }
215+ }
216+
203217function setUniElementScrollOffset (
204218 uniElement : UniElement ,
205219 res : Record < string , any >
You can’t perform that action at this time.
0 commit comments