- 需求的场景描述(希望解决的问题)
Page({
onLoad() {
wx.createIntersectionObserver().relativeToViewport({bottom: 100}).observe('.target-class', (res) => {
res.intersectionRatio // 相交区域占目标节点的布局区域的比例
res.intersectionRect // 相交区域
res.intersectionRect.left // 相交区域的左边界坐标
res.intersectionRect.top // 相交区域的上边界坐标
res.intersectionRect.width // 相交区域的宽度
res.intersectionRect.height // 相交区域的高度
})
}
})
这段代码只有在第一次进入的时候执行,第二次重新进入就不执行了。
很奇怪。求教一下。
- 希望提供的能力
onReady:function(){
var a = this;
console.log('observer:'+observer);
var observer = wx.createIntersectionObserver();
console.log('observer:' + observer);
console.log('showRecommend:' + a.data.showRecommend);
observer.relativeToViewport().observe('.applyBar', (res) => {
console.log('res.intersectionRatio:' + res.intersectionRatio);
if (res.intersectionRatio > 0 && a.data.showRecommend == 0) {
a.GetRecommendList();
}
});
},
希望帮忙看看。我刚做小程序没多久,新手。谢谢。
第二次是怎么进入的页面?是不是没有触发onLoad事件?
触发了。生命周期重新开始的。类似商品详情页,第一次点击列表A商品,进入A详情页,可以生效;然后回到列表页,点击B商品,进入B详情页,然后就不生效了。
提供一下代码片段看看(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
找到问题了。谢谢。打搅了。