见描述

- 发布:2023-08-07 20:42
- 更新:2025-09-01 16:03
- 阅读:1121
【报Bug】微信小程序使用createSelectorQuery,报错TypeError: Cannot read property '__route__' of undefined
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win11
HBuilderX类型: 正式
HBuilderX版本号: 3.8.12
第三方开发者工具版本号: 1.06.2306281
基础库版本号: 2.33.0
项目创建方式: HBuilderX
操作步骤:
预期结果:
见描述
见描述
实际结果:
见描述
见描述

1***@163.com - 在技术的道路上缓慢前进
const instance = getCurrentInstance()
uni.createSelectorQuery().in(instance)
这样试试呗

onMounted(async () => {
let height = uni.getWindowInfo().windowHeight
console.log('屏幕高度=' + height)
//await nextTick()
let instance = getCurrentInstance()
const query = uni.createSelectorQuery().in(instance);
query.select('#refresh_list')
.boundingClientRect((data) => {
console.log('节点信息=', data);
})
.exec();
})
在微信小程序上运行为null
屏幕高度=812
index.esm.js:361 节点信息= null
请教下怎么解决
-
-
回复 DCloud_UNI_JBB: 感谢指导,我也试过了不行。我后来发现把代码放在页面中可以,我之前是在自定义组件中使用,是不是它不能在自定义组件中使用
2025-04-27 09:54
-
-

以下代码测试在4.76版本的hx上运行并没有报错,可参考下方代码修改测试是否还有报错
<template>
<view style="font-size: 80rpx;">
<view id="test">首页</view>
</view>
</template>
<script setup>
import {
getCurrentInstance,
onMounted
} from 'vue';
const ins = getCurrentInstance()
onMounted(() => {
const query = uni.createSelectorQuery().in(ins.proxy)
query.select('#test').boundingClientRect(data => {
console.log("data", data);
}).exec();
})
</script>
试试试试 (作者)
可行!
2023-08-26 20:15