Skip to content

Commit a0258b5

Browse files
committed
v2.7.11-修复打开调试模式下无法获取getApp导致的报错
1 parent 6ecdf83 commit a0258b5

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

demo/z-paging-demo/uni_modules/z-paging/components/z-paging/js/z-paging-interceptor.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,25 @@ function _getApp(){
6464
// #endif
6565
}
6666

67+
// 是否可以访问globalData
68+
function _hasGlobalData() {
69+
return _getApp() && _getApp().globalData;
70+
}
71+
6772
// 添加处理函数
6873
function _addHandleByKey(key, callback) {
6974
try {
7075
setTimeout(function() {
71-
_getApp().globalData[`zp_handle${key}Callback`] = callback;
76+
if (_hasGlobalData()) {
77+
_getApp().globalData[`zp_handle${key}Callback`] = callback;
78+
}
7279
}, 1);
7380
} catch (_) {}
7481
}
7582

7683
// 获取处理回调函数
7784
function _getHandleByKey(key) {
78-
return _getApp().globalData[`zp_handle${key}Callback`];
85+
return _hasGlobalData() ? _getApp().globalData[`zp_handle${key}Callback`] : null;
7986
}
8087

8188
export default {

demo/z-paging-vue3-demo/uni_modules/z-paging/components/z-paging/js/z-paging-interceptor.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,25 @@ function _getApp(){
6464
// #endif
6565
}
6666

67+
// 是否可以访问globalData
68+
function _hasGlobalData() {
69+
return _getApp() && _getApp().globalData;
70+
}
71+
6772
// 添加处理函数
6873
function _addHandleByKey(key, callback) {
6974
try {
7075
setTimeout(function() {
71-
_getApp().globalData[`zp_handle${key}Callback`] = callback;
76+
if (_hasGlobalData()) {
77+
_getApp().globalData[`zp_handle${key}Callback`] = callback;
78+
}
7279
}, 1);
7380
} catch (_) {}
7481
}
7582

7683
// 获取处理回调函数
7784
function _getHandleByKey(key) {
78-
return _getApp().globalData[`zp_handle${key}Callback`];
85+
return _hasGlobalData() ? _getApp().globalData[`zp_handle${key}Callback`] : null;
7986
}
8087

8188
export default {

z-paging/components/z-paging/js/z-paging-interceptor.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,25 @@ function _getApp(){
6464
// #endif
6565
}
6666

67+
// 是否可以访问globalData
68+
function _hasGlobalData() {
69+
return _getApp() && _getApp().globalData;
70+
}
71+
6772
// 添加处理函数
6873
function _addHandleByKey(key, callback) {
6974
try {
7075
setTimeout(function() {
71-
_getApp().globalData[`zp_handle${key}Callback`] = callback;
76+
if (_hasGlobalData()) {
77+
_getApp().globalData[`zp_handle${key}Callback`] = callback;
78+
}
7279
}, 1);
7380
} catch (_) {}
7481
}
7582

7683
// 获取处理回调函数
7784
function _getHandleByKey(key) {
78-
return _getApp().globalData[`zp_handle${key}Callback`];
85+
return _hasGlobalData() ? _getApp().globalData[`zp_handle${key}Callback`] : null;
7986
}
8087

8188
export default {

0 commit comments

Comments
 (0)