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);
}
)