Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复页面跳转前后$uGetRect this指向错误 #1279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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