微信小程序封装接口文件 小程序

shuke 2023-2-1 202

/apis/api.js

const serverURL="http://localhost:6600";

function post(url, data = {}) {
  return new Promise(function (resolve, fail) {
    wx.showLoading({
      title: 'loading....',
    })
    wx.request({
      url: serverURL + url,
      data,
      method: "POST",
      success:(res)=> resolve(res.data),
      fail,
      complete() {
        wx.hideLoading()
      }
    })
  })
}

function get(url, data = {}) {
  return new Promise(function (resolve, fail) {
    wx.showLoading({
      title: 'loading...',
    })
    wx.request({
      url: serverURL + url,
      data,
      header:{
        Authorization:wx.getStorageSync('token')
      },
      method: "GET",
      success:(res)=> resolve(res.data),
      fail,
      complete() {
        wx.hideLoading()
      }
    })
  })
}

module.exports = {
  serverURL,
  getmove:(data)=> get("/api/getmoviepage",data),
  postLogin:(data)=>post("/api/login",data),


}


最新回复 (2)
全部楼主
  • shuke 2023-2-2
    2
    const  api=require("./apis/api.js")
  • shuke 2023-3-16
    3
    header:{
                              'content-type':'application/x-www-form-urlencoded',
                              'Authorization':'Bearer    xxxxxxxxxxxxx',
                      },
返回