简体   繁体   English

从 graphql 循环数据到 Nuxt

[英]Looping data from graphql into Nuxt

So I am a beginner at vue and was trying a small project and I have data from graphql API that i want to represent into the frontend.所以我是 vue 的初学者,正在尝试一个小项目,我有来自 graphql API 的数据,我想将这些数据表示到前端。

Initially I was presenting this data in a hard coded way in the frontend.最初,我在前端以硬编码的方式呈现这些数据。

Below presents how I fetch said data下面介绍了我如何获取所述数据

const measurements = (await useAsyncData('measurements', async () => {
      const result = await $client.request(query)
      return result
    })).data

and had my data presented on cards like so:并将我的数据显示在卡片上,如下所示:

 const cards = [
       { name: 'Fist', icon: ScaleIcon, amount: metrics.value.adminMeasure[5].value},
      { name: 'Second' icon: ScaleIcon, amount: metrics.value.adminMeasure[6].value },
       { name: 'Third',icon: ScaleIcon, amount: metrics.value.adminMeasure[0].value},
     
      
     ]

But now I want to present the data in the cards using a for loop.但现在我想使用 for 循环在卡片中显示数据。 I was thinking of for..in loop, how would i go about this?我在考虑 for..in 循环,我会怎么处理这个问题?

Assuming that you are using Vuetify card components .假设您使用的是Vuetify 卡组件

<template>
  <v-row>
    <v-col v-for="card in cards" :key="card.name" cols="12>
     <v-card class="mx-auto" max-width="344">
        <v-card-text>
          // Render content here
        </v-card-text>
     </v-card>
    </v-col>
  </v-row>
</template>

<script>
export default {
  data: (() => {
    return {
      cards: [] // Add your cards here
    };
  })
}
<script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM