taro-v2ex
taro-v2ex copied to clipboard
想问下this.$router是哪里来的?
我目前基于最新的3.0.8的版本改造这个项目,但是node_detail.tsx中的$router是从哪里来的? 谢谢。
componentWillMount() {
const { full_name } = this.$router.params; // 我不太懂这个$router是怎么来的,前端会报错
Taro.setNavigationBarTitle({
title: decodeURI(full_name),
});
}
好吧,3.0的版本接口改了,现在要这样用
import Taro, { getCurrentInstance } from "@tarojs/taro";
componentWillMount() {
const { full_name } = getCurrentInstance().router.params;
Taro.setNavigationBarTitle({
title: decodeURI(full_name),
});
}