uniapp中vue3使用uni.createSelectorQuery().in(this)报错

因为VUE3中使用setup没有this作用域,所以报错

解决办法:使用getCurrentInstance()方法获取组件实例

import { getCurrentInstance } from 'vue';

const instance = getCurrentInstance(); // 获取组件实例
const DOMArr = uni.createSelectorQuery().in(instance);
DOMArr.select('.posterMake')
	.boundingClientRect(poster => {
		posterX.value = poster.left;
	})
	.exec();

uniapp中vue3使用uni.createSelectorQuery().in(this)报错_第1张图片

你可能感兴趣的:(uni-app,vue.js,javascript)