zoukankan      html  css  js  c++  java
  • 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);
      });
    });
  • 相关阅读:
    前言
    echarts踩坑---容器高度自适应
    vue中刷新页面时去闪烁,提升体验方法
    2018.11.7
    07-sel-express 框架快速搭建案例
    第三方包 vue-resource
    zepto.js-定制zepto步骤
    CSS-单位em 和 rem
    ES6-个人学习大纲
    响应式布局
  • 原文地址:https://www.cnblogs.com/arealy/p/14215103.html
Copyright © 2011-2022 走看看