美文网首页
小程序wx.request封装

小程序wx.request封装

作者: 王小杰at2019 | 来源:发表于2019-12-27 20:47 被阅读0次

const baseUrl = 'http://localhost:8080/'
const request = (url, data, method) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      method: method,
      data: data,
      success(res) {
        resolve(res);
      }, fail(error) {
        reject(error)
      }
    })

  })
}

const get = (url, data, method) => {
  return request(url, data, 'GET')
}

const post = (url, data, method) => {
  return request(url, data, 'POST')
}

export const login = (code) => {
  console.log(code);
  get('/api/v1/account/login', { a: 'a', b: 'b' }).then(resp => {
    console.log(resp);
  })
  post('/api/v1/account/login', { a: 'a', b: 'b' }).then(resp => {
    console.log(resp);
  })
}

相关文章

网友评论

      本文标题:小程序wx.request封装

      本文链接:https://www.haomeiwen.com/subject/kxqjoctx.html