在頁面級別可以使用上拉加載onReachBottom
和下拉刷新onPullDownRefresh
,在子組件里無法觸發(fā),該如何處理
- 需在父頁面進行對這兩個事件的監(jiān)聽然后傳遞給子組件
// 父頁面
// 設置監(jiān)聽上拉加載事件
onReachBottom() {
uni.$emit('onReachBottom')
},
// 設置監(jiān)聽下拉刷新事件
onPullDownRefresh() {
uni.$emit('onPullDownRefresh')
}
- 子組件
// 子組件
beforeMount() {
// 監(jiān)聽父頁面?zhèn)鬟f的上拉加載
uni.$on('onReachBottom', () => {
console.log("到達底部,onReachBottom")
})
// 監(jiān)聽父頁面?zhèn)鬟f的下拉刷新
uni.$on('onPullDownRefresh', () => {
console.log("進行了上拉刷新,onPullDownRefresh")
})
},
destroyed() {
// 銷毀onReachBottom監(jiān)聽
uni.$off('onReachBottom')
// 銷毀onPullDownRefresh
uni.$off('onPullDownRefresh')
}