axios 默认是 Payload 格式数据请求,但有时候后端接收参数要求必须是 Form Data 格式的,所以我们就得进行转换

    1. //把数据的键值对放在form对象里面
    2. const form = new FormData()
    3. form.append('index', 1)
    4. form.append('pageSize', 10)
    5. form.append('categoryId', 0)
    6. const t = this;
    7. //照常发axios请求,数据就是form
    8. axios.post('http://localhost:7777/article/articleLists',form)
    9. .then(function (response) {
    10. console.log(response);
    11. t.articleList=response.data.data;
    12. })
    13. .catch(function (error) {
    14. console.log(error);
    15. });