用Taro写一个微信小程序——Taro3路由传参

🌲 参考https://docs.taro.zone/docs/router

1、传入参数

Taro.navigateTo({
  url: '/pages/page/path/name?id=2&type=test'
})

 

2、在跳转后的页面获取入参

import { getCurrentInstance } from '@tarojs/taro'
import React, { Component } from 'react'

export default class C extends Component {
  componentDidMount () {
    console.log(getCurrentInstance().router.params) // 输出 { id: 2, type: 'test' }
  }
}

 

📚总结

taro3以下版本通常使用「this.$router.params.参数名」方法获取入参;

taro3开始需要使用「getCurrentInstance().router.params」才能获取到。

 

End------------------------

🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲

🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸🎸

🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦🍦

 

posted @ 2021-05-11 18:33  麦豇豆  阅读(639)  评论(0编辑  收藏  举报