sylvaner
sylvaner
  • 发布:2019-07-26 15:23
  • 更新:2020-07-26 15:04
  • 阅读:1254

【报Bug】boundingClientRect 在 Typescript 下报错

分类:uni-app

详细问题描述

uni.createSelectorQuery().select().boundingClientRect() 类型报错

[内容]

mounted() {  
    this.documentList.map(item => {  
        uni.createSelectorQuery()  
            .select(`#${item.id}`)  
            .boundingClientRect(data => {  
                console.log(`#${item.id}`, data);  
            })  
            .exec();  
        return item;  
    });  
},

报错信息: Property 'exec' does not exist on type 'void'.

原因是实际上boundingClientRect返回是的void而不是文档上的「返回 NodesRef 对应的 SelectorQuery」;
(method) NodesRef.boundingClientRect(callback?: ((result: NodeInfo) => void) | undefined): void

IDE运行环境说明

[IDE版本号]
HBuilderX 2019 2.1.3.20190723

[运行端是h5或app或某个小程序?]
h5

[运行端版本号]

[项目是cli创建的还是HBuilderX创建的?如果是cli创建的,请更新到最新版cli再试]
cli创建,已经是最新版

[编译模式是老模板模式还是新的自定义组件模式?]
自定义组件模式

2019-07-26 15:23 负责人:无 分享
已邀请:
堂吉诃德

堂吉诃德 - 自学是一门艺术

哦豁,没有人回答,我也在用这个。

使用nodesRef.boundingClientRect(callback)直接报错了

this.$refs.utab.$el.boundingClientRect(data => {  
     console.log("得到布局位置信息" + JSON.stringify(data));  
     console.log("节点离页面顶部的距离为" + data.top);  
}).exec();

错误信息

{"message":"_this2.$refs.utab.$el.boundingClientRect is not a function","stack":"TypeError: _this2.$refs.u...}

该问题目前已经被锁定, 无法添加新回复