2018-01-29--AXIOS

作者: 小飞侠zzr | 来源:发表于2018-01-29 21:16 被阅读0次

    新的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])

    ....未完待续

    相关文章

      网友评论

        本文标题:2018-01-29--AXIOS

        本文链接:https://www.haomeiwen.com/subject/dhvfzxtx.html