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
taro & querySelector & refs的更多相关文章
- Taro 3.x in Action
Taro 3.x in Action React, 小程序 https://taro-docs.jd.com/taro/docs/README Taro Next 跨端, 跨框架 Taro 是一个开放 ...
- taro refs引用
创建 Refs Taro 支持使用字符串和函数两种方式创建 Ref: 使用字符串创建 ref 通过函数创建 ref(推荐) 你也可以通过传递一个函数创建 ref, 在函数中被引用的组件会作为函数的第一 ...
- Taro Next H5 跨框架组件库实践
作者:凹凸曼 - JJ Taro 是一款多端开发框架.开发者只需编写一份代码,即可生成各小程序端.H5 以及 React Native 的应用. Taro Next 近期已发布 beta 版本,全面完 ...
- $refs的用法及作用
获取DOM元素,一般用document.querySelector获取这个dom节点,然后在获取input的值 但是用ref绑定之后,就不需要在获取dom节点了,直接在上面的input上绑定input ...
- Vue.js中ref ($refs)用法举例总结
原文地址:http://www.cnblogs.com/xueweijie/p/6907676.html <div id="app"> <input type=& ...
- vue $refs的基本用法
<div id="app"> <input type="text" ref="input1"/> <butto ...
- vue & button & refs & click & bug
vue & button & refs & click & bug $refs.btn.click() ??? vue & refs $refs.btn.$em ...
- Taro自定义Modal对话框组件|taro仿微信、android弹窗
基于Taro多端实践TaroPop:自定义模态框|dialog对话框|msg消息框|Toast提示 taro自定义弹出框支持编译到多端H5/小程序/ReactNative,还可以自定义弹窗类型/弹窗样 ...
- vue中$refs的用法及作用详解
一般来讲,获取DOM元素,需要使用document.querySelector('#input1')方法去获取dom节点,然后再获取input1的值. 但是使用了ref绑定之后,我们就不需要再获取do ...
随机推荐
- 文件系统层次结构标准 Linux 系统目录结构
https://zh.wikipedia.org/wiki/文件系统层次结构标准 多数Linux发行版遵从FHS标准并且声明其自身政策以维护FHS的要求. [3] [4] [5] [6] 但截至200 ...
- redis 代码结构与阅读顺序
https://www.cnblogs.com/aixiaomei/p/6311633.html
- 初始TypeScript
什么是TypeScript? TypeScript是拥有类型系统的JavaScript的超集,可以编译成纯JavaScript: 1.类型检查:TS会在编译代码时进行严格的静态类型检查,这意味着可以在 ...
- 浅谈自动化构建之gulp
一.gulp的基本使用 gulp是目前最流行的前端自动化构建系统,核心特点高效易用.(这块不过多的废话了,直接上干货了,有兴趣的话,可以查下gulp简介) 步骤如下: yarn init -y yar ...
- 一:Spring Boot 的配置文件 application.properties
Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...
- 一块网卡配2IP地址
我们知道在Linux下网卡被称为eth0,eth1,eth2.....,所有网卡的配置文件都存储在 /etc/sysconfig/network-script/下,文件名是以ifcfg-eth0,if ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】
比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...
- c语言实现--不带头结点的单链表操作
1,不带头结点的单链表操作中,除了InitList(),GetElem(),ListInsert(),ListDelete()操作与带头结点的单链表有差别外,其它的操作基本上一样. 2,不带头结点单链 ...
- 【noi 2.6_162】Post Office(DP)
这题和"山区建小学"除了输入不同,其他都一样.(解析可见我的上一篇随笔) 但是,这次我对dis[][]加了一个优化,画一下图就可明白. 1 #include<cstdio&g ...
- Happy 2006 POJ - 2773 容斥原理+二分
题意: 找到第k个与m互质的数 题解: 容斥原理求区间(1到r)里面跟n互质的个数时间复杂度O(sqrt(n))- 二分复杂度也是O(log(n)) 容斥原理+二分这个r 代码: 1 #include ...