vue axios的使用

详细可以看: https://www.kancloud.cn/yunye/axios/234845

这里介绍日常使用得比较多的get和post:

import axios from 'axios'
//get
axios.get('url~~~', { 
    params: {
        data1: 123,
        data2: 456
    }
}).then(res => {
    console.log(res.data)
}, err => {
    console.log(err)
})
//post post参数不需要再包一层params
axios.post('url~~~', { 
    data1: 123,
    data2: 456
}).then(res => {
    console.log(res.data)
}, err => {
    console.log(err)
})

axios可以通过get/post方法,向对应url发起请求,显然返回的是一个promise

未完。。。

原文地址:https://www.cnblogs.com/amiezhang/p/8417844.html