axios入门学习笔记



Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。

一、引入axios

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

二、axios请求和响应格式

axios请求格式:
axios{
    method: 'get|post', //请求方法
    url: '', //请求地址
    params: {}, //get参数
    data: {} //post参数
})

axios响应格式:
{
    data: {},  //服务器提供响应内容
    status: 200, //服务器响应的 HTTP 状态码
    statusText: 'OK', //服务器响应的 HTTP 状态信息
    headers: {}, //服务器响应的头
    config: {}, //为请求提供的配置信息
    request: {}
}

三、axios get请求

axios({
    method: 'get',
    url: '/demo.asp',
    params: {
        domain: 'mzwu.com',
        registered: '2005-03-28'
    }
})
.then(function(response) {
    console.log(response);
})

别名axios.get:

axios.get('/demo.asp?domain=mzwu.com&registered=2005-03-28')
.then((response)=>{console.log(response)})

四、axios post请求

axios({
    method: 'post',
    url: '/demo.asp',
    data: {
        domain: 'mzwu.com',
        registered: '2005-03-28'
    }
})
.then(function(response) {
    console.log(response);
})

别名axios.post:

axios.post('/demo.asp', 'domain=mzwu.com&istered=2005-03-28')
.then((response)=>{console.log(response)})

相关链接

[1].axios中文网:http://www.axios-js.com/

评论: 0 | 引用: 0 | 查看次数: 1746
发表评论
登录后再发表评论!