let instance = axios.create({
baseURL: baseUrl,//请求基地址
timeout: 3000,//请求超时时长
url: '/url',//请求路径
method: 'get,post,put,patch,delete',//请求方法
headers: {
token: ''
},//请求头
params: {},//请求参数拼接在url上面
data: {},//请求参数放请求体里
})
/*ajax请求*/ | |
import axios from 'axios' | |
axios.defaults.baseURL = 'https://api.douban.com/v2/movie' | |
Vue.prototype.$ajax = axios |
=========================================================================================================
get
Axios.get('demo/url', {
params: {
id: 123,
name: 'Henry',
sex: 1,
phone: 13333333
}
})
delete
Axios.delete('demo/url', {
data: {
id: 123,
name: 'Henry',
sex: 1,
phone: 13333333
}
})
post
Axios.post('demo/url', {
id: 123,
name: 'Henry',
sex: 1,
phone: 13333333
})
put
Axios.put('demo/url', {
id: 123,
name: 'Henry',
sex: 1,
phone: 13333333
})
patch
Axios.patch('demo/url', {
id: 123,
name: 'Henry',
sex: 1,
phone: 13333333
})