uniapp关于请求的封装

// const baseURL = "https://xxx";
const baseURL = "https://xxx";

export default function(params) {
  const { url, data = {}, method = "GET" } = params;
  console.log(method, "method");
  const token = uni.getStorageSync("token");
  const fullURL = baseURL + url;
  return new Promise((resolve, reject) => {
    uni.request({
      url: fullURL,
      data,
      method: method.toUpperCase(),
      header: {
        Authorization: token || "",
      },
      timeout: 10000,
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
}

外部使用当前文件

import http from '当前文件路径'

 

posted @ 2021-04-01 17:00  深海里的星星i  阅读(72)  评论(0)    收藏  举报