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;
}
});
 
                                        
                                    
                                    - 发布:2020-12-08 15:15
- 更新:2020-12-08 15:15
- 阅读:1845
产品分类: 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)
 
                                                                                                                                                                                                                                                             
                                                                                                                                                                                 
             
             
             
			