Hooks的基本用法


基本使用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

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM