1.首先进行页面跳转传递参数
1 2 3 4
| Taro.navigateTo({ url:'/pages/details/index?id=1' })
|
2. 页面接收参数
例子:
类组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| import { Component } from 'react' import { View, Text } from '@tarojs/components' import { getCurrentInstance } from '@tarojs/taro'
export default class Index extends Component { $instance = getCurrentInstance()
componentDidMount () { console.log(this.$instance.router.params) }
render () { return ( <View className='index'> <Text>详情页面</Text> </View> ) } }
|
函数式组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| import React, { useState } from 'react' import { View, Text } from '@tarojs/components' import { getCurrentInstance } from '@tarojs/taro'
function Index(){ const [userName ,setUserName] = useState('Hello World!!!!')
const { router } = getCurrentInstance(); console.log(router.params)
return ( <View> <Text>{userName}</Text> </View> ) }
export default Index
|
在控制台打印都是Ok的,写的相对简单,供自己下回查阅