|
- const app = getApp()
-
- // 封装wx.request请求
- const request = (url, options) => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: `${url}`,
- method: options.method,
- data: options.method === 'GET' ? options.data : JSON.stringify(options.data),
- header: {
- 'AccessToken': wx.getStorageSync('authToken')
- },
- // AccessToken
- success(request) {
- if (request.data.code === 0) {
- resolve(request.data)
- } else {
- reject(request.data)
- }
- },
- fail(error) {
- reject(error.data)
- }
- })
- })
- }
-
- const get = (url, options = {}) => {
- return request(url, { method: 'GET', data: options })
- }
-
- const post = (url, options) => {
- return request(url, { method: 'POST', data: options })
- }
-
- module.exports = {
- get,
- post,
- }
|