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)
})
}
产品分类: 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)
1***@qq.com (作者)
最后没有在组件里面写
2024-05-21 16:56