Axios 基于Promise。在服务端它使用原生 node.js 模块创建http请求, 而在浏览器端是使用XMLHttpRequests。
例子如下:
(一)get请求
const axios=require('axios')
axios.get(‘具体请求路径‘)
.then(function(res)
{console.log(res)})
.catch(function(err){
console.log(err)})
.then(function(){
})
(二)post请求
axios.post('路径',
{ params:'' })
.then(function (res) {
console.log(res); })
.catch(function (err) {
console.log(err);
});
也可以写成另外形式:
axios({
method: 'post',
url: '路径',
data: { params: ''
} });