阿修罗
阿修罗
  • 发布:2022-02-10 09:50
  • 更新:2022-02-10 20:58
  • 阅读:751

vue3 nvue 页面调用封装时,getApp()只能用于APP this 只能用于微信小程序

分类:nvue

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

2022-02-10 09:50 负责人:无 分享
已邀请:
小枫叶

小枫叶 - 外包接单加v:wlmk1234567 注明来意

getapp在哪里调用了?

该问题目前已经被锁定, 无法添加新回复