项目场景:
组件中uni.createSelectorQuery()获取到的对象为null
vue2.0中
- 在组件內时,增加代码:in(this)
- uni.createSelectorQuery().in(this)
vue3.0中
- 由于vue3中没有this,所以使用uni.createSelectorQuery().in(this)时,会报错
- 解决的办法就是使用getCurrentInstance()方法获取组件实例。
const instance = getCurrentInstance(); // 获取组件实例
uni.createSelectorQuery().in(instance)
本文介绍了解决uni.createSelectorQuery()在不同Vue版本中获取组件实例的问题。在Vue2.0中,通过增加代码in(this)实现;而在Vue3.0中,因无this,需使用getCurrentInstance()获取组件实例。
&spm=1001.2101.3001.5002&articleId=128254003&d=1&t=3&u=e6865c2ac7a84273af98c2cf5442ac96)
1428

被折叠的 条评论
为什么被折叠?



