美文网首页
Taro 基于State的数据管理

Taro 基于State的数据管理

作者: 张思学 | 来源:发表于2020-03-30 15:30 被阅读0次

学习过react的同学一定知道 state
状态State
状态更新一定是异步的
设置状态必须用setState
-- 同步更新需要传入callBack

import Taro, { Component } from "@tarojs/taro";
import { View, Text, Button } from "@tarojs/components";
import "./index.less";

export default class Index extends Component {
  componentWillMount() {}

  componentDidMount() {}

  componentWillUnmount() {}

  componentDidShow() {}

  componentDidHide() {}

  config = {
    navigationBarTitleText: "首页"
  };
  state = {
    name: "张思学"
  };
  setName() {
    this.setState({ name: '张思学6666' },()=>{
      console.log('callBack', this.state.name);
    });
    console.log('旧的', this.state.name);
  }
  render() {
    return (
      <View className="index">
        <Text>{this.state.name}</Text>
        <Button onClick={this.setName}>click</Button>
      </View>
    );
  }
}

相关文章

网友评论

      本文标题:Taro 基于State的数据管理

      本文链接:https://www.haomeiwen.com/subject/ifsvuhtx.html