Skip to content

Commit 440d347

Browse files
committed
fix(x-mp-alipay): 修复 UniElement 获取 scrollTop、scrollLeft、scrollWidth 和 scrollHeight 属性失败的问题
1 parent 76f9333 commit 440d347

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

packages/uni-mp-vue/src/dom/utils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff 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+
203217
function setUniElementScrollOffset(
204218
uniElement: UniElement,
205219
res: Record<string, any>

0 commit comments

Comments
 (0)