Skip to content

Conversation

@faye-ops
Copy link

@faye-ops faye-ops commented Jul 6, 2023

$uGetRect this指向错误

期望的结果是什么?

当页面跳转之后,在返回原页面,正常获取节点布局信息

实际的结果是什么?

当页面跳转之后,在返回原页面,this指向已经发生改变,无法获取节点布局信息

修复方法

应该在原页面调用api时传入this,同时SuGetRect做出以下改动:

$uGetRect(selector, all, that) {
  return new Promise(resolve => {
    uni.createSelectorQuery().
    in(that?that:this)[all ? 'selectAll' : 'select'](selector)
    .boundingClientRect(rect => {
      if (all && Array.isArray(rect) && rect.length) {
        resolve(rect)
      }
      if (!all && rect) {
        resolve(rect)
    }).exec()
  })
}

功能即可正常

@faye-ops faye-ops changed the title 修复页面跳转前后this指向不一致的问题 修复页面跳转前后$uGetRect this指向错误 Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants