jiangchengfeiyi-xiaochengxu/uni_modules/zp-mixins/lifecycle/pageLifetimes.js
2025-04-02 23:45:33 +08:00

33 lines
749 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 组件pageLifetimes处理需在页面生命周期里调用
* @param {Object} node
* @param {Object} lifeName
*/
function handlePageLifetime(node, lifeName) {
node.$children.map(child => {
if (typeof child[lifeName] == 'function') child[lifeName]()
handlePageLifetime(child, lifeName)
})
}
export const pageLifetimes = {
onLoad() {
// #ifndef APP || MP-MP-WEIXIN || MP-KUAISHOU
uni.onWindowResize((res) => {
handlePageLifetime(this, "handlePageResize")
})
// #endif
},
onShow() {
handlePageLifetime(this, "handlePageShow")
},
onHide() {
handlePageLifetime(this, "handlePageHide")
},
onResize() {
// #ifdef APP || MP-MP-WEIXIN || MP-KUAISHOU
handlePageLifetime(this, "handlePageResize")
// #endif
}
};