1.请求模块
import axios from 'axios' const request = axios.create({ baseURL : '',//请求的域名地址 timeout : 5000, })request.interceptors.request.use((config)=>{
//开启loading 禁止背景点击 return config },(err)=>{ return Promise.reject(err) })
request.interceptors.response.use((response)=>{ //关闭loading const res = response.data if(res.code!==200){
return Promise.reject(res.msg) } return res },(err)=>{
return Promise.reject(err) })
export default request
2.api封装
//存储跟登录相关的api import request from '@/utils/request' export const login = ()=>{ return request.get('/login') } ///////////////////////////// //使用 import {login} from '@/api/login' login()
标签:Vue,return,err,res,request,api,模块,login From: https://www.cnblogs.com/qinlinkun/p/18072420