微信小程序
小程序基础库: 2.13.1
使用框架: React
https://taro-docs.jd.com/taro/docs/hooks/#usescope
这里没有 useScope 相关说明了,那么该怎么替代 this.$scope 呢
使用函数组件相关 hook 实现class组件中的 this.$scope
在 @tarojs/taro 中找不到 useScope 相关hook了
Taro v3.0.14
Taro CLI 3.0.14 environment info:
System:
OS: macOS 10.15.7
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.3 - ~/.n/bin/node
npm: 6.14.8 - ~/.n/bin/npm
npmPackages:
@tarojs/components: 3.0.13 => 3.0.13
@tarojs/mini-runner: 3.0.13 => 3.0.13
@tarojs/react: 3.0.13 => 3.0.13
@tarojs/runtime: 3.0.13 => 3.0.13
@tarojs/taro: 3.0.13 => 3.0.13
@tarojs/webpack-runner: 3.0.13 => 3.0.13
babel-preset-taro: 3.0.13 => 3.0.13
eslint-config-taro: 3.0.13 => 3.0.13
react: ^16.10.0 => 16.13.1
npmGlobalPackages:
typescript: 4.0.2
Taro3 不需要 scope 了,相关的 API 也不用传入了
Taro3 不需要 scope 了,相关的 API 也不用传入了
那应该怎么在函数式组件中使用this.$scope呢
不需要scope的,因为已经不再编译成小程序的components的组件规范
createSelectorQuery 如何限制获取组件内的 节点呢?
在使用小程序自定义tabbar 的时候也要用 this.$scope.getTabBar(),没有 useScope 怎么获取呢
把以前的方案废除了,现在新的方案是什么?useScope 我看源码返回了一个undefined?
可以使用 useRef 替代
const ref = useRef();
<View ref={ref }>
</View>
可以限制获取组件内节点
貌似不行。ref获取到的是Taro Element 实例
我想这个一个非常重要的问题,期待过渡方案。
Most helpful comment
那应该怎么在函数式组件中使用this.$scope呢