uniappパッケージajax

  1. utilsでrequest.jsファイルを作成する

エクスポート const request1 = (url, メソッド = 'get', params = {}) => {     const トークン = uni.getStorageSync('token') || ''; //获取トークン     uni.showLoading({         title: "加ダウンロード中"     });     return new Promise((解決、拒否) => {         uni.request({             url: myApi.hostBaseUrl + url,             メソッド: メソッド,             ヘッダー: {                 'X-Token': token             },             データ: {                 ...params             },             success(res) {                 // console.log('request', res, '网络请求')                 if (res.data.

















                    ログイン情報 = uni.getStorageSync('ログイン情報');
                    if (loginInfo == '') {                         uni.redirectTo({                             url: '/pages/myUser/wxSign/wxSign?fromUrl=' +                                 encodeURIComponent(getCurrentPages()[                                     getCurrentPages()                                     .length - 1].$page.fullPath)                         })                     } else {                         wxlogin(loginInfo)                     }                 } else {                     if (res.data.code != 200) {                         // uni.showToast({












                        // タイトル: res.data.msg,
                        // アイコン: 'none'
                        // })
                        uni.showModal({                             title: 'プロンプト',                             content: res.data.msg,                             showCancel: false,                             success: function(res) {                                 if (res.confirm) {                                     console.log('ユーザーが [OK] をクリックしました');                                 }                             }                         });                         return                     }











                    解決(解決);
                }
            }、
            失敗(エラー) {                 拒否(エラー);             },             complete() {                 setTimeout(() => {                     uni.hideLoading();                 }, 1200)             }         });     }); };









おすすめ

転載: blog.csdn.net/weixin_67091603/article/details/128233432