taro-v2ex icon indicating copy to clipboard operation
taro-v2ex copied to clipboard

想问下this.$router是哪里来的?

Open cshenger opened this issue 4 years ago • 1 comments

我目前基于最新的3.0.8的版本改造这个项目,但是node_detail.tsx中的$router是从哪里来的? 谢谢。

componentWillMount() {
    const { full_name } = this.$router.params; // 我不太懂这个$router是怎么来的,前端会报错
    Taro.setNavigationBarTitle({
      title: decodeURI(full_name),
    });
  }

cshenger avatar Sep 09 '20 10:09 cshenger

好吧,3.0的版本接口改了,现在要这样用

import Taro, { getCurrentInstance } from "@tarojs/taro";

componentWillMount() {
    const { full_name } = getCurrentInstance().router.params;
    Taro.setNavigationBarTitle({
      title: decodeURI(full_name),
    });
  }

cshenger avatar Sep 10 '20 02:09 cshenger