Skip to content

Commit b498e11

Browse files
committed
refactor(x): 调整 getElementById 实现
1 parent 4ab6233 commit b498e11

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

packages/uni-app-plus/src/x/api/dom/getElementById.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ import { getCurrentPage } from '@dcloudio/uni-core'
55
export const getElementById = defineSyncApi<GetElementById>(
66
'getElementById',
77
(id: string.IDString | string): UniElement | null => {
8-
const page = (getCurrentPage() as unknown as UniPage).vm
8+
const page = getCurrentPage() as unknown as UniPage
99
if (page == null) {
1010
return null
1111
}
12-
13-
const bodyNode = page.$el?.parentNode
14-
if (bodyNode == null) {
15-
console.warn('bodyNode is null')
16-
return null
17-
}
18-
return bodyNode.querySelector(`#${id}`)
12+
return page.getElementById(id)
1913
}
2014
)

packages/uni-app-plus/src/x/framework/page/setup.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,7 @@ export function setupXPage(
5050
return new UTSJSONObject(pageVm.$basePage.options)
5151
},
5252
})
53-
uniPage.getElementById = (
54-
id: string.IDString | string
55-
): UniElement | null => {
56-
const containerNode = pageVm.$el?.parentElement
57-
if (containerNode == null) {
58-
console.warn('bodyNode is null')
59-
return null
60-
}
61-
return containerNode.querySelector(`#${id}`)
62-
}
53+
6354
uniPage.vm = pageVm
6455
uniPage.$vm = pageVm
6556

0 commit comments

Comments
 (0)