3 axios({})基本使用

1 get请求

            axios({
                method: 'GET',
                url: 'http://localhost:3000/posts',
            }).then(resp => {
                console.log(resp)
            })
        })
image.png

2 post请求

            axios({
                method: 'POST',
                url: 'http://localhost:3000/posts',
                data: {
                    "title": "今日重大新闻",
                    "author": "佚名"
                }
            })

发送post请求后数据增加:


image.png

3 修改

            axios({
                method: "PUT",
                url: 'http://localhost:3000/posts/3',
                data: {
                    "title": "今日小新闻",
                    "author": "佚名"
                }
            }).then(resp => {
                console.log(resp)
            })
image.png

4 删除

            axios({
                method: "DELETE",
                url: 'http://localhost:3000/posts/3'
            }).then(resp => {
                console.log(resp)
            })
image.png

附录:

index.html





    
    
    
    Document
    



    
    
    
    
    



你可能感兴趣的:(3 axios({})基本使用)