封裝小程式網路請求
阿新 • • 發佈:2018-11-14
/* 1.對小程式wx.require的封裝 */ class Ajax{ constructor(dev=true){ this.base = dev ? 'https://生產環境' : 'https://開發環境'; this.token = ""; this.sv = "1.0.0"; } // 引數處理 handleData(data){ data.token = this.token; if(this.sv){ data.sv = this.sv; } }// promise封裝 ajax(url,data={},type='get'){ this.handleData(data); return new Promise((resolve,reject)=>{ wx.request({ url:this.base + url, data:data, method:type, success:res =>{ resolve(res);/* 1.埋個頁面,方便稽核 2.當提交稽核時,讓後臺把所有的介面都返回10007狀態 */ if (res.data.errno == 10007) { wx.reLaunch({ url: '/pages/index/index', //簡單的頁面,應對稽核 }); } }, fail:rej=>{ reject(rej); } }) }) } }
經歷幾周的開發,小程式終於上線啦。
在開發過程中遇見了很多的問題,解決了問題,學到了一些新的思路。
下班前,記錄一波一點收穫