标签 axios 下的文章

axios 文档


axios

Promise based HTTP client for the browers and Node.js

install axios

npm i -S axios

发送请求

// index.js

let axios = requrie('axios')

// get 请求
axios.get('/user?id=123')
    .then(res => console.log(res))
    .catch(err => console.log(err))

// 或者这样 
axios.get('/user', {
    params: {
        id: 123
    }
})
.then(res => console.log(res))
.catch(err => console.log(err))

// post 请求
axios.post('/user', {
    name: 'tao',
    age: 20
})
.then(res => console.log(res))
.catch(err => console.log(err))

// 使用 Promise.all() 发送多个并发请求
function getName() {
    return axios.get('/user/123/name')
}

function getAge() {
    return axios.get('/user/123/age')
}

axios.all([getName(), getAge()])
    .then(axios.spread((acct, perms) => {

    }))