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的更多相关文章

  1. Taro 3.x in Action

    Taro 3.x in Action React, 小程序 https://taro-docs.jd.com/taro/docs/README Taro Next 跨端, 跨框架 Taro 是一个开放 ...

  2. taro refs引用

    创建 Refs Taro 支持使用字符串和函数两种方式创建 Ref: 使用字符串创建 ref 通过函数创建 ref(推荐) 你也可以通过传递一个函数创建 ref, 在函数中被引用的组件会作为函数的第一 ...

  3. Taro Next H5 跨框架组件库实践

    作者:凹凸曼 - JJ Taro 是一款多端开发框架.开发者只需编写一份代码,即可生成各小程序端.H5 以及 React Native 的应用. Taro Next 近期已发布 beta 版本,全面完 ...

  4. $refs的用法及作用

    获取DOM元素,一般用document.querySelector获取这个dom节点,然后在获取input的值 但是用ref绑定之后,就不需要在获取dom节点了,直接在上面的input上绑定input ...

  5. Vue.js中ref ($refs)用法举例总结

    原文地址:http://www.cnblogs.com/xueweijie/p/6907676.html <div id="app"> <input type=& ...

  6. vue $refs的基本用法

    <div id="app"> <input type="text" ref="input1"/> <butto ...

  7. vue & button & refs & click & bug

    vue & button & refs & click & bug $refs.btn.click() ??? vue & refs $refs.btn.$em ...

  8. Taro自定义Modal对话框组件|taro仿微信、android弹窗

    基于Taro多端实践TaroPop:自定义模态框|dialog对话框|msg消息框|Toast提示 taro自定义弹出框支持编译到多端H5/小程序/ReactNative,还可以自定义弹窗类型/弹窗样 ...

  9. vue中$refs的用法及作用详解

    一般来讲,获取DOM元素,需要使用document.querySelector('#input1')方法去获取dom节点,然后再获取input1的值. 但是使用了ref绑定之后,我们就不需要再获取do ...

随机推荐

  1. HTML 5 学习第二课

    元素:<p>+++++++++</P> 全部内容 标签:<P></P> 属性:标签内部的内容 eg:<img src=" "& ...

  2. Golang之垃圾回收

    本篇主要是参考了: http://legendtkl.com/2017/04/28/golang-gc/ 说是参考,但其实基本上是原封不动. GC算法简介: 1. 引用计数 引用计数的思想非常简单:每 ...

  3. SpringMVC传递JSON数据

    文章目录 一.前后端传递和接收JSON数据 1:是要Ajax默认格式来传递数据(*) 2:使用application/json格式来传递数据 二.spring-web.xml中需要如下配置 一.前后端 ...

  4. GeoMesa Spark

    GeoMesa Spark 一.Spark JTS 1.1 示例 1.2配置 1.3 地理空间用户定义的类型和功能 1.4 geojson输出 1.5 Building 二.Spark Core 2. ...

  5. Java排序算法(一)冒泡排序

    一.测试类SortTest  import java.util.Arrays; public class SortTest { private static final int L = 20; pub ...

  6. MiniProfiler性能分析工具— .Net Core中用法

    前言: 在日常开发中,应用程序的性能是我们需要关注的一个重点问题.当然我们有很多工具来分析程序性能:如:Zipkin等:但这些过于复杂,需要单独搭建. MiniProfiler就是一款简单,但功能强大 ...

  7. HDU6311 Cover【欧拉路径 | 回路】

    HDU6311 Cover 题意: 给出\(N\)个点的简单无向图,不一定联通,现在要用最少的路径去覆盖所有边,并且每条边只被覆盖一次,问最少路径覆盖数和各条路径 \(N\le 10^5\) 题解: ...

  8. C. New Year Book Reading

    New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n b ...

  9. - 迷宫问题 POJ - 3984 bfs记录路径并输出最短路径

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...

  10. Typora Themes自定义

    Typora Themes自定义 Typora 支持css样式,自定义主题十分方便,修改自己的css文件,再放入其themes文件夹,重启Typora,即可看到自定义主题. Typora 官网,自定义 ...