2***@qq.com
2***@qq.com
  • 发布:2023-11-21 16:45
  • 更新:2023-11-22 09:47
  • 阅读:405

uni.createSelectorQuery().in(this).select() 报错 [object DOMException] at view.umd.min.js:1

分类:uni-app

app端 vue2
这个是长按事件回调,id是通过v-for进行绑定的,并不存在id重复的情况

//长按事件回调  
openMessageBox(e) {  
    let id = e.currentTarget.id;  
    console.log(id)  
    const query = uni.createSelectorQuery().in(this);  
    query.select('#'+id).boundingClientRect(data => {  
         console.log("得到布局位置信息" + JSON.stringify(data));  
         console.log("节点离页面顶部的距离为" + data.top);  
    }).exec();  
}

执行此代码,会报错,报错信息 [object DOMException] at view.umd.min.js:1
并且只能打印出 id
有人知道这是什么原因吗
我只想长按一个元素的时候,获取该元素的坐标(相对于屏幕)以及宽高,有别的解决方案吗?

2023-11-21 16:45 负责人:无 分享
已邀请:
喜欢技术的前端

喜欢技术的前端 - QQ---445849201

检查一下id 不能是数字  
<template>  
    <view class="content">  
        <view class="view" v-for="(item,index) in list" :key="index" :id="item.id" @longpress="openMessageBox($event)">  
            {{item.name}}  
        </view>  
    </view>  
</template>  
<script>  
    export default {  
        data(){  
            return {  
                list:[  
                    {id:'id11',name:'11'},  
                    {id:'id22',name:'22'}  
                ]  
            }  
        },  
        methods: {  
            openMessageBox(e) {  
                let id = e.currentTarget.id;  
                console.log(id)  
                const query = uni.createSelectorQuery().in(this);  
                query.select('#' + id).boundingClientRect(data => {  
                    console.log("得到布局位置信息" + JSON.stringify(data));  
                    console.log("节点离页面顶部的距离为" + data.top);  
                }).exec();  
            }  
        }  
    }  
</script>  
<style>  
    .content{  
        padding: 30rpx;  
    }  
    .view {  
        background-color: #999;  
        margin-top: 30rpx;  
    }  
</style>

要回复问题请先登录注册