12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import axios from 'axios'
- const service = axios.create({
- baseURL: process.env.BASE_API, // api 的 base_url
- timeout: 5000 // 请求超时时间
- })
- console.log(123123,process.env)
- // request拦截器
- service.interceptors.request.use(
- config => {
- if (localStorage.getItem('token')) {
- config.headers['token'] = localStorage.getItem('token'); // 让每个请求携带自定义token 请根据实际情况自行修改
- }
- return config
- },
- error => {
- // Do something with request error
- console.log(error) // for debug
- Promise.reject(error)
- }
- )
- // response 拦截器
- service.interceptors.response.use(
- response => {
- const res = response.data
- if (res.code !== 200) {
- console.log('error',res.message);
- } else {
- return response.data
- }
- },
- error => {
- console.log('err' + error) // for debug
- return Promise.reject(error)
- }
- )
- export function getExampleData (code) {
- return service({
- url: '/skillInfo',
- method: 'get',
- params: {
- code
- }
- })
- }
|