【问题标题】:Fetching spreadsheet data as JSON with axios and Vue.js使用 axios 和 Vue.js 以 JSON 格式获取电子表格数据
【发布时间】:2021-03-16 23:03:54
【问题描述】:

我正在尝试以 JSON 格式从谷歌工作表中获取行/数据。

<script>
const url =
  "https://spreadsheets.google.com/feeds/list/1NXF6G5npwcGeo2v_9tSDzieSHjxe4QtA-I9iPzHyvMk/1/public/values?alt=json";
const axios = require("axios").default;
export default {
  data: () => ({
    entries: [],
  }),
  mounted() {
    axios.get(url).then((response) => {
      this.entries = response.data;
    });
  },
};
</script>

JSON 树(?)不确定它叫什么。我对此真的很陌生。看起来像

如何在我的 vue 应用上调用它

<v-simple-table class="mt-5">
  <tbody>
    <tr v-for="column in entries" :key="column.EmployeeID">
      <td>{{ column.EmployeeID }}</td>
      <td>{{ column.EmployeeName }}</td>
      <td>{{ column.RaffleTickets }}</td>
      <td>{{ column.TotalPromoter }}</td>
      <td>{{ column.TotalAHTGoal }}</td>
    </tr>
  </tbody>
</v-simple-table>

不确定我与想要的结果有多接近。

【问题讨论】:

  • 我正在尝试做同样的事情,但我收到以下错误:“访问 XMLHttpRequest at 'accounts.google.com/…{ID}/1/public/values?alt%3Djson&followup= spreadsheets.google.com/feeds/list{ID}/1/public/values?alt%3Djson&ltmpl=sheets'(重定向自'spreadsheets.google.com/feeds/list{ID}/1/public/values?alt=json')来自原点'localhost:8080'被 CORS 政策阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。想法?
  • 我已经可以通过 url 访问文档的 json 版本(已发布和创建的共享链接),并从 axios 请求中删除了所有标头参数,但此处的任何其他信息也无济于事..

标签: json vue.js google-sheets axios


【解决方案1】:

根据你应该做的响应数据结构:

 this.entries = response.data.feed.entry;

然后在模板中:

  <tr v-for="column in entries" :key="column.gsx$employeeid.$t">
      <td>{{ column.gsx$employeeid.$t}}</td>
      <td>{{ column.gsx$employeename.$t}}</td>
      <td>{{ column.gsx$raffletickets.$t}}</td>
      <td>{{ column.gsx$totalpromoter.$t }}</td>
      <td>{{ column.gsx$totalahtgoal.$t }}</td>
    </tr>

【讨论】:

  • 好的。如果你能纵容我的天真。如何用它制作一个 v-data-table?我在数据字段中添加了标题:[{ text: "Employee ID", value: "gsx$employeeid" } 等...并添加了 。但是网络显示像 100 行 [object Object]。
  • 好的,你错过了添加$t[{ text: "Employee ID", value: "gsx$employeeid.$t" },
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-11
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
  • 2023-04-11
  • 1970-01-01
相关资源
最近更新 更多