在app.js中
api: function(method, url, data, callback) { var c = Object.assign({ key: this.globalData.accesskey, openid: this.globalData.openid }, data); console.log(c) wx.request({ url: this.globalData.apiurl + url, method: method, data: c, header: { 'content-type': method == 'GET' ? 'application/json' : 'application/x-www-form-urlencoded', // 'Accept': 'application/json', // 'content-type': 'application/json' }, dataType: 'json', success: function(res) { callback(res); }, fail: function(err) { wx.showToast({ title: err, icon: 'none' }) } }) }, globalData: { userInfo: null, apiurl: 'https://20.celong.cn', accesskey: 'hahaha', openid: '', session_key: '' }
使用方法
// 接口 - 获取当期杂志 app.api('GET', '/GetData/index', {model:"zoom",limit:1}, (res) => { var ps = res.data.data[0].photo; var pic = app.photo(ps); res.data.data[0]['photos'] = pic; _this.setData({view:res.data.data[0]}); console.log(res.data.data[0]); })