vue axios网络模块封装

request.js

import axios from 'axios'

export function request(config, success, failure) {
  const instance = axios.create({
    baseURL: 'http://123.207.32.32:8000',
    timeout: 1000,
  });

  instance(config)
    .then(res => {
      success(res);
    })
    .catch(err => {
      failure(err);
    })
}

main.js

import {request} from './network/request.js'

request({
    method: 'get',
    url: '/home/data',
    params: {
      type: 'sell',
      page: 1
    }
  },
  res => {
    console.log(res);
  },
  err => {
    console.error(err);
  }
)
posted @ 2021-07-15 19:22  thomas_blog  阅读(39)  评论(0编辑  收藏  举报