发表于: 2019-11-30 22:15:03

0 1281


今天完成的事情:完成复盘申请,准备方案设计

明天计划的事情:

遇到的问题:

收获:学习Vue的异步请求写法


Vue异步请求

使用fetch方法

//get

fetch('url').then(res=>res.json()).then(res=>{console.log(res)})

fetch('url').then(res=>res.text()).then(res=>{console.log(res)})

//post

fetch('url',{

    method: 'post',

    headers: {

        "Content-Type": "application/x-www-form-urlencoded"

    },

    body: "key1=value1&key2=value2",

    //credentials:"include"//fetch默认不带cookie设置这个后可以发送cookie

}).then(res=>res.json()).then(res=>{console.log(res)});

fetch('url',{

    method: "post",

    headers: {

        "Content-Type": "application/json"

    },

    body: JSON.stringfy({

        key1:value1,

        key2:value2

    }).then(res=>res.json()).then(res=>{console.log(res)})

})

使用axios

//get

axios.get("url").then(res=>{

    console.log(res.data)

})

//post

axios.post('url',{

    key1:value1,

    key2:value2

}).then(res=>{

    console.log(res.data)

})

axios({

    url:'url',

    method: 'get',

    headers:{

        '需要的字段'

    }

}).then(res=>{

    console.log(res.data)

})



返回列表 返回列表
评论

    分享到