vue2.0使用axios发送请求及传参问题

vue2.0初学者使用axios发送请求,一般会自己建立一个请求文件方便自己做测试用,在传参的过程按F12可能会发现参数没有传过去.

如果是get请求,传参方式如下(此处以vue 中mothods方法里的函数为例):

methods: {
  loginFun(){
    let _this = this;
    _this.$axios.get('../../../static/test.json',{
      params:{
        loginName:this.username,
        password:this.password
      }
    })
      .then(function (response) {
      console.log(response);
    }).catch(function (error) {
      console.log(error)
    })

  }
}

 

如果是post:

methods: {
  loginFun(){
    let _this = this;
    _this.$axios.get('/api/user',{
        loginName:this.username,
        password:this.password
    })
      .then(function (response) {
      console.log(response);
    }).catch(function (error) {
      console.log(error)
    })

  }
}

如果是自己练习,没有后台接口的话,建议用get请求,这样不会报错

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值