uni-app nvue页面使用uni.createSelectorQuery().in(this).select(".warn")报错Cannot read property 'ref' of undefined

uni-app nvue页面使用uni.createSelectorQuery().in(this).select(".warn")报错Cannot read property ‘ref’ of undefined

问题描述

uni.createSelectorQuery().in(this).select(".warn");执行时报错TypeError: Cannot read property 'ref' of undefined

uni.createSelectorQuery().in(this).select("#warn");没有问题,见图1

一模一样的代码在Vue下执行没有问题,见图2

代码

<template>
    <view>
        <view class="warn" @tap="navToAddr" id="warn">
            <text>测试</text>
        </view>
    </view>
</template>

<script>
export default {
    mounted() {
        this.test('mounted');
    },
    onReady(e) {
        this.test('ready');
    },
    methods: {
        test(e) {
            try {
                const query1 = uni.createSelectorQuery().in(this).select(".warn");
                query1.boundingClientRect(data => {
                    console.log("得到布局位置信息2" + e + JSON.stringify(data));
                    console.log("节点离页面顶部的距离为2" + e + data.top);
                }).exec();
            } catch (e) {
                console.log(e)
            }
            try {
                const query1 = uni.createSelectorQuery().in(this).select("#warn");
                query1.boundingClientRect(data => {
                    console.log("得到布局位置信息1" + e + JSON.stringify(data));
                    console.log("节点离页面顶部的距离为1" + e + data.top);
                }).exec();
            } catch (e) {
                console.log(e)
            }
        }
    }
}
</script>

<style>
.warn {
    width: 120px;
    height: 30px;
}
</style>

图片

图1

图2


更多关于uni-app nvue页面使用uni.createSelectorQuery().in(this).select(".warn")报错Cannot read property 'ref' of undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html

8 回复

哪位大佬帮忙看看啊,昨天搞了一天了,都没整明白

更多关于uni-app nvue页面使用uni.createSelectorQuery().in(this).select(".warn")报错Cannot read property 'ref' of undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html


同样的问题 nvue还是慎用,现在先加个定时器再获取吧

咋解决的???/

咋解决的

我的情况是vue页面使用$nextTick与createSelectorQuery,调整下一个nvue页面会一直报 10:48:27.955 [Vue warn]: Error in nextTick: “TypeError: Cannot read property ‘ref’ of undefined” 10:48:27.968 TypeError: Cannot read property ‘ref’ of undefined 10:48:28.156 [Vue warn]: Error in nextTick: “TypeError: Cannot read property ‘ref’ of undefined” 10:48:28.173 TypeError: Cannot read property ‘ref’ of undefined 10:48:28.356 [Vue warn]: Error in nextTick: “TypeError: Cannot read property ‘ref’ of undefined” 10:48:28.377 TypeError: Cannot read property ‘ref’ of undefined

解决了吗?我也遇到了

回复 张亚如: 解决了,排除法查了很久终于解决了。。。但是我忘了什么导致的了 尴尬

回复 天狐: 没事没事,我也解决了

回到顶部