主要编译在app.js里面
/*
*微信小程序的数据请求的再次封装
*/
wxajax(url,method,data,callback,errfun,token){
wx.request({
url: `${url}`,
data: data,
header: {
"content-type": method == 'get' ? 'application/json' :'application/x-www-form-urlencoded',
"Accept": 'application/json',
'token' : token
},
method: method,
dataType: 'json',
responseType: 'text',
success: function(res) {
callback(res)
},
fail: function(err) {
errfun(err)
}
})
},
/*
*微信小程序alert弹出的封装
*/
wxshowtoast(star){
wx.showToast({
title: star,
icon: 'none',
duration: 2000
})
}
在每个页面的js文件里面调用
getAPP().wxshowtoast("字符串")