taro的createSelectorQuery()坑

小程序框架入门简介 1. 小程序简介 小程序就是基于微信平台的H5轻应用,微信将系统底层功能(设备、位置、媒体、文件等)和微信自身功能(登录、支付、分享等)封装成相应API供小程序调用。 2. 小程序基本概念 开发工具:为了配合小程序开发,微信专门配备了自己的开发工具,自行选择对应版本安装。 创建项目应用:安装完成后,打开并扫码登录。小程序发布需要企业级的认证公众号,所以个人订阅号是不能发布的。所以我这里选择无AppID,创建项目选择一个本地空文件夹,勾选创建quick start 项目生成一个demo。 编写小程序: de 阅读详情

(本来不想写的,但是这个坑害我花费了很多时间,写一下让大家避免踩坑)

taro版本是:2.2.7,如果其他版本,其实解决的办法大同小异,逻辑上差不多

问题:

  1. taro的createSelectorQuery在web端获取数据不正确,在小程序没问题?
  2. createSelectorQuery获取dom实例信息
    setTimeout(()=>{
          Taro.nextTick(() => {
            // 使用 Taro.nextTick 模拟 setData 已结束,节点已完成渲
           Taro.createSelectorQuery().in(this.$scope).select('.yx__adaptiveHeight')
              .boundingClientRect()
              .exec(res => {
                const obj = res[0]
                this.domInfo = obj
                console.log(this.domInfo,'+++++++==',res)
              })
          })
        },20000)
    

    原因:h5获取数据不正确,加setTimeout延迟处理,小程序获取正常。可不加settimeout。

如何在类组件里使用this.createSelectorQuery().in(this)拿到的也是null? 🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值。 阅读详情

相关推荐

STM32 Boot程序实战:从启动流程到安全跳转机制解析

本文深入解析STM32 Boot程序的核心作用与安全跳转机制,涵盖启动流程、内存管理、中断向量表重定向及固件验证等关键环节。通过实战案例分享如何实现可靠的固件升级与故障回退策略,避免设备变砖风险,提升嵌入式系统稳定性。

pluto的博客 780

Taro.createSelectorQuery()

方法,那么查询结果中的元素就是指定节点的位置、大小信息。如果调用了多个查询方法,那么查询结果中的元素就是一个数组,数组中的每个元素对应一个查询方法的结果。需要注意的是,执行查询操作是异步的,因此回调函数的执行时机也是异步的。参数是一个数组,数组中的元素是查询结果。对象,它提供了一种方法,可以查询页面中的元素信息,比如位置、尺寸等等。方法执行查询操作,并将查询结果作为参数传递给回调函数。对象中的一个方法,用于执行查询操作,并返回结果。方法获取该节点的位置、大小等信息。方法选取指定的元素节点,再通过。

weixin_54079103的博客 1636

HIL(硬件在环)技术汇总梳理

HIL(Hardware-in-the-Loop)测试领域的知名公司有dSPACE、NI、Vector和speedgoat等,本文是针对这几家HIL技术的对比分析。

Mr.Cssust的博客 3686

Taro.createSelectorQuery获取元素

先输出的是[null] 这并不是我们想要的数据, 各位要是稍微留心 会很容易发现 输出为[null]的原因是因为 DOM 在此时没有渲染完成,因此 Taro.createSelectorQuery()找不到对应的DOM节点,所以才会输出[null]的结果,返回一个 SelectorQuery 对象实例。可以在这个实例上使用 select 等方法选择节点,并使用 boundingClientRect 等方法选择需要查询的信息。

m0_49471668的博客 1450

统信UOS开发环境支持Java

集成了JDK和多种IDE,为开发者提供了从代码编写、编译、调试到部署的一站式开发解决方案。

RZer的博客 2254

自绘CListCtrl时发现ON_WM_MEASUREITEM_REFLECT和DrawItem(LPDRAWITEMSTRUCT lpMeasureItemStruct) 无响应

自绘CListCtrl时发现ON_WM_MEASUREITEM_REFLECT和DrawItem(LPDRAWITEMSTRUCT lpMeasureItemStruct) 无响应 一般情况下,我们都是在 dialog 里面 放一个 list 控件,然后 用自己的类绑定自己的自绘对象,如同下面: 1.  在 dialog 里面 加一个 list 列表 2. 然后 绑定这个列表 哈哈...

mfreesky的专栏 2170

Taro.createSelectorQuery()踩坑之路

其实Taro.createSelectorQuery()这个API的坑很浅的,不算很难。 一开始刚使用的时候大家发现 const query = Taro.createSelectorQuery().select(className).boundingClientRect(); query.exec(res => { console.log(res); ...

初竹殇的博客 1万+

[计算机头歌]爬虫进阶

【代码】爬虫进阶。

M_inherit的博客 921

Taro-Taro.createSelectorQuery()

【代码】Taro-Taro.createSelectorQuery()

weixin_46479909的博客 519

【AMD | Docker】超级全面版本:在Docker中验证AMD GPU移动显卡可用性的方法

1. 安装ROCm Docker支持 ■AMD GPU驱动 ■ROCM ■Docker 2. 配置Docker使用ROCm 3. 使用官方ROCm Docker镜像 4. 使用Docker CLI参数访问GPU

静谧、淡雅 684

【永磁同步电机】simulink永磁同步电机PMSM矢量控制【含Matlab源码 7372期】

simulink永磁同步电机PMSM矢量控制 完整的代码,方可运行;可提供运行操作视频!适合小白!

订阅付费专栏Matlab(奶茶价版),可赠送奶茶价版付费专栏指定代码1份; 1029

Taro+react开发(72):Taro.createSelectorQuery

Taro.createSelectorQuery() 返回一个 SelectorQuery 对象实例。可以在这个实例上使用 select 等方法选择节点,并使用 boundingClientRect 等方法选择需要查询的信息。

歌谣的博客 860

YOLOv5基于深度学习的道路缺陷检测系统

然而,由于长期的自然侵蚀、车辆磨损等因素,道路表面容易出现裂缝、坑洼等缺陷。这些缺陷不仅会影响驾驶舒适性,还可能引发交通事故,尤其是在恶劣天气或夜间行车条件下。随着人工智能技术的快速发展,基于深度学习的道路缺陷检测技术能够在降低人力成本的同时提高检测效率,为道路维护提供了新的解决方案。本项目构建了基于YOLOv5的道路缺陷检测系统,结合PyQt5开发了用户友好的UI界面,具备实时检测和图片分析功能。工具对图片进行标注,生成YOLO格式的标注文件。上传包含道路裂缝或坑洼的图片,系统会标注出缺陷的位置及类别。

YOLO 1076

Taro+react开发(73):Taro.createSelectorQuery

Taro.nextTick(() => { // 使用 Taro.nextTick 模拟 setData 已结束,节点已完成渲染 Taro.createSelectorQuery() .in(isH5 ? this : this.$scope) .select(".dynamic-detail-content-text") .fields({ size: true }) .exec(res => {...

歌谣的博客 827

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

createSelectorQuery获取对象为null

wx.createSelectorQuery().in(this).select(’#’ + id); Taro小程序同理 const query = wx.createSelectorQuery().in(this); query .select(`#${id}`) .fields({ node: true, size: true, }) .exec((res) => { .

weixin_46449470的博客 2847

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

taro、uniapp、微信小程序导航栏双向联动

Taro双向联动(跨版导航)效果图功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出不懂Promise.all()用法,可以去官网看看 效果图 我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能

天涯尽头的拾荒者的博客 1275

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

使用Taro.createSelectorQuery动态计算tab切换效果tab的宽度

const { itemMargin, padding } = this.props; let width = 0; this.systemInfo = await Taro.getSystemInfo(); this.scale = this.systemInfo.screenWidth / 750; console.log('屏幕缩放比-------->', this.systemInfo); const query = Taro.createS...

TangAcrab的博客 1212

taro.createSelectorQuery is not a function【Taro-ui AtAccordion组件问题】

utils.ts:21 Uncaught TypeError: taro.createSelectorQuery is not a function 问题

这是个什么博客 459

taro 获取dom节点信息

直接在生命周期函数中获取值为null 方式一:再加个延迟200毫秒的函数获取 1、创建选择器 const query = Taro.createSelectorQuery(); 将选择器的选取范围更改为自定义组件component内.(初始时,选择器仅选取页面范围的节点,不会选取任何自定义组件中的节点) const query = Taro.createSelectorQuery().in(this); 2、查询 获取单个 query.select('选择器').boundingCli

weixin_43294560的博客 8036

react &amp; taro 报错 _createSelectorQuery is not defined解决办法

在项目的node_modules文件下找到 taro-ui 3.0.0 的 package.json,在里面增加一个入口: "main:h5": "dist/index.esm.js" 让 taro 把 index.esm.js 作为 taro-ui 的入口即可。

QingHan_wow的博客 2295

Taro获取元素位置尺寸信息

如果用useRef和document.getElementById()拿到的也一直是TaroElement,无法拿到想要的元素位置尺寸等信息。 下面正确代码: const selectorQueryClientRect = ( selector: string, ): Promise<NodesRef.BoundingClientRectCallbackResult> => new Promise(resolve => { const query = Ta.

qq_36014502的博客 5149

Taro 项目怎么获取元素的高度和视口高度

最近做小程序,用的Taro,需要设置空状态居中显示,因为空状态出现的地方不一样,所以需要动态设置,那么就需要获取元素的高度来计算文档翻了一遍也没有找到,原生js获取高度得到的是null,百度了下一下Taro 怎么获取元素的高度,教程里全都是用原生js,不知道他们怎么得到的查不到的时候就要想到了强大的chatgpt4,然后去问了一下,果真问到了。

forteenBrother的博客 4674

taro ScrollView 实现页面内容增加自动上滑到最顶部

移动端内容自动滚动

weixin_43886340的博客 2405

Taro 在小程序和H5的踩坑记录

Taro 踩坑记录 1、@taro/cli版本必须跟package.json的版本一致,否则使用Taro.xxx会报「 is not a function 」的错误 例如:「_tarojs_taro__WEBPACK_IMPORTED_MODULE_2___default.a.navigateTo is not a function」 解决方案1:重新按照官网文档初始化项目 解决方案2:package.json 文件引入的 Taro 的版本号改成与 Taro cli 工具的版本号保...

爱吃烧烤的技术渣的博客 4649

taro 主题切换_Taro 滚动切换tab页

import React, { Component } from 'react'import { View, Text, ScrollView } from '@tarojs/components'import { createSelectorQuery } from '@tarojs/taro'import './index.scss'const tabList = [{name: '头', v...

weixin_30082413的博客 773

createSelectorQuery返回null

需要在nextTick中获取元素信息,dom渲染后获取 Taro.nextTick(async () => { const query = Taro.createSelectorQuery() query.select('#slide_text').boundingClientRect(rec => { console.log(rec) }).exec() console.log(query) })

noMore_h的博客 745
上一篇: [mobx.array] Attempt to read an array index (2) that is out of bounds (1). Please
Anguler_
博客等级 码龄10年 20粉丝 34原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值