如何在 Function 函数组件中 获取 $scope & $router?
-
如何在 Function 函数组件中 获取 $scope & $router?
如果不能在函数组件中 获取到这两个内容的话, hooks function 的使用范围应该会受到影响的吧?
-
暂时可以用 this.$router 来获取到,后续会提供更 Hook 的写法
-
@隔壁老李 所有说, 如果组件用到了 $scope & $router 目前还是只能用 class 类编写了吧, 那就只能等待后续的更新了, 谢谢了.
-
@littcc_m 不是,你可以直接在函数式组件中使用 this.$router
-
@隔壁老李 可以拿到, 感谢.
-
@隔壁老李 在 如何在 Function 函数组件中 获取 $scope & $router? 中说:
this.$router
this.$router 和 this.$scope 好像函数组件中都无法获取呢
-
@jwan3453 注意不要使用箭头函数定义组件, 使用function 可以的
-
可以用 useScope
import Taro, { useScope } from '@tarojs/taro'
const scope = useScope();