1***@qq.com
1***@qq.com
  • 发布:2023-07-28 14:42
  • 更新:2024-04-05 20:53
  • 阅读:293

【报Bug】uniapp+vue3自定义组件中使用uni.createSelectorQuery报错

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 10

第三方开发者工具版本号: 1.06.2306020

基础库版本号: 2.33.0

项目创建方式: CLI

CLI版本号: @vue/cli 5.0.8

示例代码:

import {ref, getCurrentInstance } from 'vue'

let testClick = () => {
const instance = getCurrentInstance()
let query = uni.createSelectorQuery().in(instance)
query.select('#test').boundingClientRect()
query.exec(res => {
console.log(res)
})
}

操作步骤:

页面引入自定义组件,组件里面通过点击事件里面调用uni.createSelectorQuery()api来获取对应元素的高宽

预期结果:

[{
bottom: 294
dataset: {}
height: 50
id: "test1"
left: 40
right: 90
top: 244
width: 50
}]

实际结果:

TypeError: Cannot read property 'route' of null
at vendor.js? [sm]:1529
at Array.forEach (<anonymous>)
at initComponentMocks (vendor.js? [sm]:1528)
at Object.newIn [as in] (vendor.js? [sm]:1537)
at testClick (test.js? [sm]:10)
at test.js? [sm]:22
at callWithErrorHandling (vendor.js? [sm]:2843)
at callWithAsyncErrorHandling (vendor.js? [sm]:2851)
at Function.invoke (vendor.js? [sm]:5934)
at f (WASubContext.js?t=wechat&s=1690514235727&v=2.33.0:1)(env: Windows,mp,1.06.2306020; lib: 2.33.0)

bug描述:

uniapp+vue3自定义组件使用uni.createSelectorQuery()无法获取元素对应的数据

2023-07-28 14:42 负责人:无 分享
已邀请:
肖建军

肖建军

遇到同一问题

要回复问题请先登录注册