vue3 nvue 页面调用封装时,
getApp()只能用于APP
this 只能用于微信小程序
页面调用代码 =========================================
getBase(){
//#ifdef MP
const that = this;
//#endif
//#ifndef MP
const that = getApp();
//#endif
that.http('company/appBase', {key:''}).then(res => {
this.Company = res.data;
uni.setStorageSync('Company', res.data);
uni.setStorageSync('AuntList', '');
uni.setStorageSync('ClientList', '');
uni.stopPullDownRefresh();
})
}
http封装代码 ============================================
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
app.config.globalProperties.http = (url, data, method='get') => {
if( data != undefined ){
uni.showLoading({mask:true});
method = 'post';
}
return new Promise((resolve, reject) => {
uni.request({
url: 'https://jz.hulianhujia.cn/api.' + url,
method: method,
data:data,
header:{
token:JSON.stringify(uni.getStorageSync('Token')),
},
success: (res) => {
if( res.statusCode == 200 ){
resolve(res.data);
return;
}
// console.log(res);
// console.log(data);
uni.showToast({
title: 'State:' + res.statusCode,
icon:'none',
});
},
fail:(err) => {
uni.getNetworkType({
success: function (res) {
uni.showToast({
title: '当前网络连接已断开', // + res.networkType,
icon:'none',
});
}
});
reject(err)
},
complete: (res) => {
if( method == 'post' ){
uni.hideLoading();
}
}
})
})
};
return {
app
}
}
// #endif
1 个回复
小枫叶 - 外包接单加v:wlmk1234567 注明来意
getapp在哪里调用了?