首页 > 解决方案 > 如何从vue axios响应中检索表的数字列名的值

问题描述

所以我的表结构如下

编号 | 姓名 | 1 | 2 | 3 | 4 | created_at | 更新时间

我想从 vue axios 调用的响应对象中获取第 1、2、3、4 列的值。

axios.get('/someAPIpage/').then(response => {
    this.name = response.data[0].name;
    this.a1 = response.data[0].1;
    this.a2 = response.data[0].2;
    this.a3 = response.data[0].3;
    this.a4 = response.data[0].4;
  });

但我没有成功,这可能是因为我的列名是数字。那么我怎样才能得到这些数字列值呢?任何帮助表示赞赏。

标签: vue.js

解决方案


使用括号表示法

axios.get('/someAPIpage/').then(response => {
  this.name = response.data[0].name;
  this.a1 = response.data[0]['1'];
  this.a2 = response.data[0]['2'];
  this.a3 = response.data[0]['3'];
  this.a4 = response.data[0]['4'];
});

推荐阅读