|
- const postResquest = (url, token, message, postData, doSuccess, doFail) => {
- let body={...postData};
- if (message != "") {
- wx.showLoading({
- title: message,
- })
- }
- wx.request({
- //项目的真正接口,通过字符串拼接方式实现
- url: url,
- header: {
- "content-type": "application/json;charset=UTF-8",
- "token": token
- },
- data: body,
- method: 'POST',
- success: function (res) {
- //参数值为res.data,直接将返回的数据传入
- if (message != "") {
- wx.hideLoading()
- };
- doSuccess(res.data);
- },
- fail: function (res) {
- if (message != "") {
- wx.hideLoading()
- };
- wx.showToast({
- title: '网络错误',
- })
- },
- })
- }
- const getResquest = (url, token, message, getData, doSuccess, doFail) => {
- let body = { ...getData };
- if (message != "") {
- wx.showLoading({
- title: message,
- })
- }
- wx.request({
- url: url,
- header: {
- "content-type": "application/json;charset=UTF-8",
- "token": token
- },
- data: body,
- method: 'GET',
- success: function (res) {
- if (message != "") {
- wx.hideLoading()
- };
- doSuccess(res.data);
- },
- fail: function (res) {
- if (message != "") {
- wx.hideLoading()
- };
- wx.showToast({
- title: '网络错误',
- })
- },
- })
- }
- module.exports = {
- postResquest: postResquest,
- getResquest: getResquest
- }
|