新的ajax请求方式,支持prominse
get请求
// 为给定 ID 的 user 创建请求
axios.get('/url?ID=1') .then(function (res) {
console.log(res);
}).catch(function (err) {
console.log(err);
});
// 可选地,上面的请求可以这样做
axios.get('/url', {
params: {
id: 1
}
}).then(function (res) {
console.log(res);
}) .catch(function (err) {
console.log(err);
});
post请求
axios.post('/url', {
firstName: 'zzr',
lastName: 'r'
}) .then(function (res) {
console.log(res);
}) .catch(function (err) {
console.log(err);
});
同时发送多个请求
function one() {
return axios.get('/url1/zzr');
}
function two() {
return axios.get('/url2/12345/ghl');
}
axios.all([one(), two()]).then(axios.spread(function (oneback, twoback) {
// 两个请求现在都执行完成
}));
配置使用
方式一
// 发送 POST 请求
axios({
method: 'type',
url: '/url/zzr',
data: {
firstName: 'zzr',
lastName: 'ghl'
}
});
方式二
axios(url,[ config])
....未完待续
网友评论