Taro next版本调用Taro.createSelectorQuery返回结果为null
-
无论是在函数式组件中,还是改为class组件的didMount中,打印都是null。
是不是我使用姿势有问题
在非next版本下是可以打印的
// 页面组件中 function Index() { // 获取tab的物理属性 useEffect(() => { const query = Taro.createSelectorQuery() const tab = query.select(‘#tab’) console.log(tab) tab.boundingClientRect(rect => { console.log(rect) // 打印为null }).exec() }, []) return( <View className="container"> // ... <View id="tab"><Tab /></View> </View> ) }
-
使用Taro.createSelectorQuery().in(this.$scope)试试,我是这么解决的。
https://nervjs.github.io/taro/docs/apis/interface/wxml/selectorQuery_in.html#docsNav
-
next的vue版本怎么传,this.$scope在vue下是undefined