taro & querySelector & refs
taro & querySelector & refs
delayQuerySelector
https://github.com/NervJS/taro-ui/blob/dev/src/common/utils.ts#L18
function delayQuerySelector(
self,
selectorStr: string,
delayTime = 500
): Promise<Array<execObject>> {
const $scope = ENV === Taro.ENV_TYPE.WEB ? self : self.$scope
const selector: SelectorQuery = Taro.createSelectorQuery().in($scope)
return new Promise(resolve => {
delay(delayTime).then(() => {
selector
.select(selectorStr)
.boundingClientRect()
.exec((res: Array<execObject>) => {
resolve(res)
})
})
})
}
refs
https://nervjs.github.io/taro/docs/ref.html
https://nervjs.github.io/taro/docs/ref.html#通过函数创建-ref
函数创建 ref
// 不管在任何情况下,Taro 都推荐你使用函数的方式创建 ref
// 自定义组件, 父组件
class MyComponent extends Component {
roar () {
// 会打印 `miao, miao, miao~`
this.cat.miao()
}
refCat = (node) => this.cat = node // `this.cat` 会变成 `Cat` 组件实例的引用
render () {
return <Cat ref={this.refCat} />
}
}
// 子组件
class Cat extends Component {
miao () {
console.log('miao, miao, miao~')
}
render () {
return <View />
}
}
Taro.createRef
// 自定义组件, 父组件
class MyComponent extends Component {
this.cat = Taro.createRef()
roar () {
// 会打印 `miao, miao, miao~`
this.cat.current.miao()
}
render () {
return <Cat ref={this.cat} />
}
}
// 子组件
class Cat extends Component {
miao () {
console.log('miao, miao, miao~')
}
render () {
return <View />
}
}
bug
https://github.com/NervJS/taro/issues/4832
https://github.com/NervJS/taro/issues/4851
https://github.com/NervJS/taro/issues/610
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/12623918.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2019-04-02 Data Structures & js &ES 6 & ES next
2019-04-02 DNS_PROBE_FINISHED_NXDOMAIN & MacOS
2016-04-02 How to fix locked SD card All In One
2016-04-02 Centos 7 环境下,如何使用 Apache 实现 SSL 虚拟主机 双向认证 的详细教程:
2016-04-02 VI & VIM 使用教程:命令详解大全 & 图解 VI & VIM All In One
2016-04-02 Linux 命令详解教程:cp/mv/rm 对文件和文件夹进行复制、移动(重命名)、删除 All In One