首页 > 技术文章 > Hooks的基本用法

lvxisha 2020-05-22 16:50 原文

基本使用demo

import Taro, { useState, useEffect,useRouter  } from '@tarojs/taro'
import { useSelector } from '@tarojs/redux'


const Index = ()=>{
  
    const userInfo = useSelector(state => state.user)
    const [height, setHeight] = useState('')
    const [value,setValue]=useState('')
    const {params} = useRouter();//相当于 this.$router.params
    console.log(params)
    //useEffect 相当于生命周期中的 componentWillMount
    useEffect(() => {
        setHeight(Taro.getSystemInfoSync().windowHeight)
  //进入页面初始化函数,也放在这里执行
        
    }, [])
  
return(
  <View style={'min-height:' + height + 'px'} className="container">
     姓名{userInfo.name}
  </View>
)
}
Index.config = {
    navigationBarTitleText: '导航栏标题'
}
Index.propTypes = {}
Index.defaultProps = {}
export default Index

  

推荐阅读