3***@qq.com
3***@qq.com
  • 发布:2021-06-04 17:48
  • 更新:2023-01-19 10:52
  • 阅读:1215

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

分类:nvue

<view class="warn" @tap="navToAddr" id="warn"><text>测试</text></view>
用uni.createSelectorQuery().in(this).select(".warn");exec时报错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"); // 这里要加上select  
                    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"); // 这里要加上select  
                    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>
2021-06-04 17:48 负责人:无 分享
已邀请:
3***@qq.com

3***@qq.com (作者)

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

DuD

DuD - 任何不快乐的时光都是浪费。——Any unhappy is a waste of time.

同样的问题 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

  • 张亚如

    解决了吗?我也遇到了

    2023-11-16 17:12

  • 天狐

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

    2024-02-22 15:57

要回复问题请先登录注册