zoukankan      html  css  js  c++  java
  • taro refs引用

    Taro 支持使用字符串和函数两种方式创建 Ref:

    1. 使用字符串创建 ref
    2. 通过函数创建 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 Components {
      miao () {
        console.log('miao, miao, miao~')
      }
    
      render () {
        return <View />
      }
    }

    .

  • 相关阅读:
    vue promise
    vue 数组操作
    vue登录注册切换的坑
    筆記連接
    vue配置jquery和bootstarp
    css的寬高約束
    css框模型
    css居中flex
    css居中
    遍历forEach与map的区别-forEach踩坑记
  • 原文地址:https://www.cnblogs.com/crazycode2/p/10146967.html
Copyright © 2011-2022 走看看