vue:axios

1:引入axios依赖包

2:import axios from 'axios'

axios请求方式分三部分:axios请求主体,then请求成功,catch请求失败

get请求方式:
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});

// Optionally the request above could also be done as
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});

post请求方式:
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});

猜你喜欢

转载自www.cnblogs.com/llqwm/p/9145210.html