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

子组件获取元素高度异常2.0版本 #2251

Closed
52javascript opened this issue Jul 16, 2019 · 3 comments
Closed

子组件获取元素高度异常2.0版本 #2251

52javascript opened this issue Jul 16, 2019 · 3 comments

Comments

@52javascript
Copy link

let query = wx.createSelectorQuery().in(this)
let _this = this
console.log(query.select)
query.select('#move-box').boundingClientRect(function (rect) {
console.log(rect)
_this.maxWidth = rect.width
console.log(_this.maxWidth)
}).exec(res => {
console.log(res)
})

ready生命周期中,在子组件获取元素高度, 控制台

An SelectorQuery call is ignored because no proper page or component is found. Please considering using SelectorQuery.in to specify a proper one.

如果不使用in(this), 获取的rect是null

@52javascript
Copy link
Author

2.0版本

@52javascript 52javascript changed the title 子组件获取元素高度异常 子组件获取元素高度异常2.0版本 Jul 16, 2019
@52javascript
Copy link
Author

let query = wx.createSelectorQuery().in(this.$wx) 改成this.$wx就行

@Gcaufy
Copy link
Collaborator

Gcaufy commented Jul 18, 2019

this 拿到是是 wepy 实例, this.$wx 才是小程序的实例

@Gcaufy Gcaufy closed this as completed Jul 18, 2019
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

No branches or pull requests

2 participants