新建network文件夹及request.js
import axios from 'axios' export function request(config){ //创建axios实例 const instance = axios.create({ baseURL: 'http://123.207.32.32:8000', timeout: 5000 }) //发生真正的网络请求 return instance(config); }
发送请求的代码
import {request} from './network/request' request({ url:'/home/data' }).then(res => { console.log(res) }).catch(err => { console.log(err) })
标签:axios,封装,network,request,instance,import,config From: https://www.cnblogs.com/ixtao/p/16930948.html