第四节、fetch axios 的使用

fetch 的使用

 fetch("./json/test.json").then(res=>res.json()).then(res=>{
                    console.log(res.data.films)
                    this.datalist = res.data.films
                })

// post-1
         fetch("**",{
             method:'post',
             headers: {
                "Content‐Type": "application/x‐www‐form‐urlencoded"
             },
            body: "name=kerwin&age=100",
            credentials:"include"
        }).then(res=>res.json()).then(res=>{console.log(res)});
      
        // post-2
         fetch("**",{
             method:'post',
             headers: {
                "Content‐Type": "application/json"
             },
            body: JSON.stringify({
                myname:"kerwin",
                myage:100
            })
        }).then(res=>res.json()).then(res=>{console.log(res)});

axios的使用

axios.get("./json/test.json").then(res=>{
                    console.log(res.data.data.films) // axios 自动包装data属性 res.data
                    this.datalist = res.data.data.films
                }).catch(err=>{
                    console.log(err);
                })

posted @ 2020-04-18 15:31  战胜自已  阅读(87)  评论(0)    收藏  举报