• js 封装 get /POST 请求


    // get请求
    export const get = ({ url, params = {}, headers = {}, title = '加载中' }) => new Promise((resolve, reject) => {
      loading.open(title);
      axios.get(url, {
        params,
        headers,
      }).then((res) => {
        if (res.status == 200) {
          resolve(res.data);
        } else {
          reject(res.data);
        }
        loading.close();
      }).catch((err) => {
        reject(err);
        loading.close();
      });
    });
    
    // post请求
    export const post = ({ url, params = {}, title = '加载中', config = {} }) => new Promise((resolve, reject) => {
      loading.open(title);
      axios.post(url, params, config).then((res) => {
        if (res.status == 200) {
          resolve(res.data);
        } else {
          reject(res.data);
        }
        loading.close();
      }).catch((err) => {
        reject(err);
        loading.close();
      });
    });
    // get请求
    export const getWithOutLoading = ({ url, params = {}, headers = {} }) => new Promise((resolve, reject) => {
      axios.get(url, {
        params,
        headers,
      }).then((res) => {
        if (res.status == 200) {
          resolve(res.data);
        } else {
          reject(res.data);
        }
      }).catch((err) => {
        reject(err);
      });
    });
    
    // post请求
    export const postWithOutLoading = ({ url, params = {}, config = {} }) => new Promise((resolve, reject) => {
      axios.post(url, params, config).then((res) => {
        if (res.status == 200) {
          resolve(res.data);
        } else {
          reject(res.data);
        }
      }).catch((err) => {
        reject(err);
      });
    });
  • 相关阅读:
    第三次作业
    第二次作业
    第一次作业
    软件工程第0次作业
    第四次作业
    第三次作业
    第二次作业
    第一次作业
    第零次作业
    第四次软件工程作业
  • 原文地址:https://www.cnblogs.com/arealy/p/14215103.html
Copyright © 2020-2023  润新知