【问题标题】:I can not catch response.data in axios我无法在 axios 中捕获 response.data
【发布时间】:2018-06-23 09:11:53
【问题描述】:

在我的 Vuetify 应用程序中,我发送一个 GET 和服务器响应,如下所示:

然后在 axios 中,我尝试使用 response.data.Autorizado 捕获该值并且不捕获。但是如果我只使用response.data,则显示数据,但显然服务器返回了大量数据,我想分发数据。

这是我的 axios 方法:

      CargarCuenta(){
  this.$Progress.start();
    axios.get("Cuenta/Cuenta?rfc="+this.selectCuentas, {
      headers:{
        Authorization : "Bearer "+localStorage.getItem("token")
      }
    }).then(response =>{
      this.$Progress.finish();
      console.log(response.data);
      this.autorizado = response.data.Autorizado;
    }).catch(error => {
      this.$Progress.finish();
      console.log(error.response);
      this.snackbar = true;
      this.textSnackbar = error.response.data.Message;
    })
  }

this.autorizado 位于 data() 返回中,在模板中我这样使用它:{{autorizado}}

【问题讨论】:

    标签: vue.js axios vuetify.js


    【解决方案1】:

    该控制台日志[{...}] 表示您有一个包含对象的数组。所以可能:[{Autorizado:true}]。没有response.data.Autorizado,但应该有response.data[0].Autorizado

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-02
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      • 2021-07-27
      • 1970-01-01
      • 2021-05-02
      相关资源
      最近更新 更多