Taro.createIntersectionObserver 如果是函数组件,怎么获取this?
-
import Taro from '@tarojs/taro'
const observer = Taro.createIntersectionObserver(this, { thresholds: [0], observeAll: true }) // 函数组件的this是哪个?
-
taro3.0.14 测试了函数式组件和类组件,都不执行,心累,不知道怎么用,uniapp里面很容易就配置出来了
-
@kerr_weijie 在 Taro.createIntersectionObserver 如果是函数组件,怎么获取this? 中说:
createIntersectionObserver
Taro.createIntersectionObserver(this.$scope).relativeToViewport({bottom: 0}).observe('.desc', res => {
用这个可以,文档写的不清晰。我查阅了很多资料后发现这样可以
-
@dadadada2x 在 Taro.createIntersectionObserver 如果是函数组件,怎么获取this? 中说:
this.$scope
这个this.$scope在函数式组件怎么获取呀
-
@dadadada2x 请问能贴一下demo代码吗
-
2.x函数组件
import {useScope} from '@tarojs/taro'
const scope=useScope()
Taro.createIntersectionObserver(scope)类组件
Taro.createIntersectionObserver(this.$scope)3.x函数组件不清楚,可能router对象能拿到