const observer = uni.createIntersectionObserver(this)
.relativeToViewport()
.observe('.mounting-menu', data => {
console.log(123, data);
if (data.intersectionRatio < 1) {
this.mountingMenuShow = true;
} else {
this.mountingMenuShow = false;
}
});
![我是饿额](https://img-cdn-tc.dcloud.net.cn/account/identicon/cf907b2ae04c7a0c83c787cb72df5af3.png)
- 发布:2020-12-08 15:15
- 更新:2020-12-08 15:15
- 阅读:1600
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 2.9.8
第三方开发者工具版本号: 1.03.2011120
基础库版本号: 2.9.2
项目创建方式: HBuilderX
示例代码:
操作步骤:
const observer = uni.createIntersectionObserver(this)
.relativeToViewport()
.observe('.mounting-menu', data => {
console.log(123, data);
if (data.intersectionRatio < 1) {
this.mountingMenuShow = true;
} else {
this.mountingMenuShow = false;
}
});
const observer = uni.createIntersectionObserver(this)
.relativeToViewport()
.observe('.mounting-menu', data => {
console.log(123, data);
if (data.intersectionRatio < 1) {
this.mountingMenuShow = true;
} else {
this.mountingMenuShow = false;
}
});
预期结果:
不出现报错信息,调试可以看到源码,createIntersectionObserver能起作用
不出现报错信息,调试可以看到源码,createIntersectionObserver能起作用
实际结果:
运行报错,调试看不到源码,createIntersectionObserver不能起作用
运行报错,调试看不到源码,createIntersectionObserver不能起作用
bug描述:
使用uni.createIntersectionObserver(this)会报错
vendor.js:3686 [Vue warn]: Property or method "toJSON" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
(found in pages/index/index.vue)
![](http://img-cdn-tc.dcloud.net.cn/uploads/questions/20201208/9cabf4b8ae4dab01b40d65f27b0c20e2.jpg)
![](http://img-cdn-tc.dcloud.net.cn/uploads/questions/20201208/68969818e1ca03cdf968f295c9986b2e.jpg)