Skip to content

Commit

Permalink
fix: 优化获取nvue元素
Browse files Browse the repository at this point in the history
  • Loading branch information
jry committed Jul 31, 2024
1 parent cd4e920 commit 91c9671
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,14 @@
// #endif
// #ifdef APP-NVUE
dom.getComponentRect(this.$refs.header, res => {
let headerRef = this.$refs.header
if (!headerRef) {
resolve({
width: 0,
height: 0
})
}
dom.getComponentRect(headerRef, res => {
resolve(res.size)
})
// #endif
Expand Down
11 changes: 9 additions & 2 deletions src/uni_modules/uview-plus/libs/mixin/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ export const mixin = defineMixin({
let selectorNvue = selector.substring(1) // 去掉开头的#或者.
let selectorRef = this.$refs[selectorNvue]
if (!selectorRef) {
console.log('不存在元素,请检查是否设置了ref属性' + selectorNvue + '。')
resolve({})
// console.log('不存在元素,请检查是否设置了ref属性' + selectorNvue + '。')
resolve({
with: 0,
height: 0,
left: 0,
right: 0,
top: 0,
bottom: 0
})
}
dom.getComponentRect(selectorRef, res => {
// console.log(res)
Expand Down

0 comments on commit 91c9671

Please sign in to comment.