taro clock组件

Posted on 2020-11-03 23:58  猫头唔食鱼  阅读(83)  评论(0编辑  收藏  举报

taro的语法和react相似

import React, { Component } from 'react'
import { View, Text } from '@tarojs/components'

export default class Index extends Component {
  constructor(props){
    super(props)
    this.state = {date: new Date()};
  }

  componentWillMount () { }

  componentDidMount () {
    // 每秒执行一次
     setInterval(() => {
      this.setState({
        date: new Date()
      })
    }, 1000);
  }

  render () {
    return (
      <View>
        {this.state.date.toLocaleString('chinese',{hour12:false}).split(' ')[1]}
      </View>
    )
  }
}