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