最近再用uniapp,结果发现子组件没有页面级生命周期 ,onReachbotton没办法直接使用,所以用了子组件监听父组件选项卡触底事件。
父页面
<!--这里用的uniapp里的uview框架的选项卡,配置省略-->
<swiper-item class="swiper-item">
<!-- 查看文档,用的是@scrolltolwer这个选项卡触底,绑定事件-->
<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="moreList">
<view class="page-box">
<!--因为选项卡里的内容太多,所以我提成不同的组件页面了-->
<ycyx :PageNum="PageNum"></ycyx>
</view>
</scroll-view>
</swiper-item>
// 遥测越线
import ycyx from '../../../../components/telemetry-ycyx/telemetry-ycyx.vue';
export default {
components: {
ycyx, //注册自定义组件,
},
data() {
return {
PageNum: 1 //页数
};
},
methods: {
moreList() {
//this.PageNum = this.PageNum + 1;
console.log('触底了')
}
}
};
</script>
子页面
export default {
props: ["PageNum"],
created: function() {
uni.$on('moreList', function(data) {
console.log('我听到出题了' + data.msg)
})
console.log(this.PageNum)
},
watch: {
PageNum(val) {
console.log("子组件", val)
this.cur = val;
this.inquire()
}
}
}