axios中的GET POST PUT PATCH

1.GET:用域获取数据
2.POST:用于提交数据
3.PUT :更新数据(吧所有数据推送到后端)
4.PATCH:更新数据(只推送修改的数据到后端)
5.DELETE:删除数据
一个简单的请求
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

axios({
      method:'GET',
      url:'/data.json',
      params:{
      //传递的参数
      id:12
      //在URL中为
      //http://localhost:8080/data.json?id=12
      }
    })
    .then(res=>{
      console.log(res);
    })
    .catch(err=>{
      console.log(err);
    })
    //当然这个也可以这样写
    /*let request=axios.create({
    	baseURL:"http://localhost:8080",
    	timeout:1000
    })
    request.get("/data.json").then.....*/

POST方法提交

 axios({
            method:'POST',
            url:'/post',
            data:data
            //提交的数据用data表示
        })
        .then(res=>{
            console.log(`res ->${res}`);
        })
        .catch(err=>{
            console.log(err);
        })

PUT请求和PATCH请求

axios({
            method:'PUT',
            url:'/put'
        })
        .then(res=>{
            console.log(`res ->${res}`);
        })
        .catch(err=>{
            console.log(err);
        })
        axios({
            method:'PATCH',
            url:'/patch'
        })
        .then(res=>{
            console.log(`res ->${res}`);
        })
        .catch(err=>{
            console.log(err);
        })

这里params和data的区别就是params是在URL进行参数传递的,而data不是

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值