Request.js wraps the page

export default function wxRequest(data, params, method) { const app = getApp(); Const baseUrl = app.globaldata. baseUrl return new Promise((resolve, reject) => {wx.showloading ({title: 'loading ', mask: true }) wx.request({ url: baseUrl + data, data: params, method: method ? method : "POST", header: { 'content-type': 'application/json', 'access_token': wx.getStorageSync('access_token') }, success: res => { wx.hideLoading() if (res.data.code == 0) { resolve(res) } else if (res.data.code == -1) { Wx.removestoragesync ('access_token') app.wxlogin () reject(res)} else {wx.showmodal ({title: 'prompt ', content: res.data.msg, confirmColor: "#FF9829", showCancel: false }) reject(res) } }, fail: Err => {wx.hideloading () wx.showmodal ({title: 'prompt ', content:' Network error, server request failed ', confirmColor: "#FF9829", showCancel: false }) } }) }) }Copy the code

Refer to page

import wxRequest from ".. /.. /utils/request" const app = getApp();Copy the code

Analog interface

wxRequest(`Order/AuditFailure? id=${this.data.auditid}`, {}, "POST").then(res => { })Copy the code