2***@qq.com
2***@qq.com
  • 发布:2023-08-03 16:12
  • 更新:2023-08-03 16:21
  • 阅读:513

uni.createSelectorQuery 嵌套使用循环输出并崩溃

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

PC开发环境操作系统版本号:

HBuilderX类型: 正式

HBuilderX版本号: 3.8.7

浏览器平台: Chrome

浏览器版本:

项目创建方式: HBuilderX

示例代码:
const query = uni.createSelectorQuery().in(this);  
query.select('.content').boundingClientRect(content => {  
  console.log('content高度'+content.height);  
  query.select('#box').boundingClientRect(box => {  
    console.log('box高度'+box.top);  
  }).exec();  
}).exec();

操作步骤:
const query = uni.createSelectorQuery().in(this);  
query.select('.content').boundingClientRect(content => {  
  console.log('content高度'+content.height);  
  query.select('#box').boundingClientRect(box => {  
    console.log('box高度'+box.top);  
  }).exec();  
}).exec();

预期结果:

预期输出两个高度

实际结果:

循环控制台输出,直到开发工具崩溃

bug描述:

当声明一个uni.createSelectorQuery方法
但是嵌套使用时,会无限循环,直到开发工具崩溃
必须声明两个 uni.createSelectorQuery方法

2023-08-03 16:12 负责人:无 分享
已邀请:
2***@qq.com

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

偶尔遇到这个bug,不过不修复也并不影响,我只是提出一下,这样使用有问题,希望这对你们有所帮助

喜欢技术的前端

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

这样写试试

const query1 = uni.createSelectorQuery();    
const query2 = uni.createSelectorQuery();    
query1.select('.content').boundingClientRect(content => {    
     console.log('content高度'+content.height);    
    query2.select('#box').boundingClientRect(box => {    
        console.log('box高度'+box.top);    
     }).exec();    
}).exec();

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