1

我想构建一个适用于 json 或 YAML 文件的网格应用程序。

我想从 Vue 组件中获取位于“./data/”文件夹中的文件的值并保留 graphQL 数据层。换句话说,从文件中公开 graphQL 数据。

profile.json

{
    "name": "Lorem"
}

配置文件

{
    "layout": "default",
    "theme": "blue"
}

我想以这样的方式访问名称值:

$page.data.profile.name
$page.data.config.theme

或者

$data.profile.name
$data.config.theme

我要处理 @gridsome/source-filesystem 和 @gridsome/transformer-json 插件吗?或者也许在服务器中手动添加“数据”集合并为每个文件添加新节点?

我已经测试了两者并探索graphQL API返回错误:“位置0的JSON中的意外令牌<”

谢谢

4

1 回答 1

0

如果你有本地文件,你可以这样添加它们:

import temperatures from '~/data/four.json'
import east from '~/data/east.json'
import southwest from '~/data/southwest.json'
import whd from '~/data/whd.json'
import thirteen from '~/data/thirteen.json'

export default {
  data () {
    return {
      temperatures,
      east,
      thirteen,
      whd,
      southwest,
    }
  },

基本上我在我的 pages 目录中创建了一个数据文件夹,然后将文件放在它们的目录中。然后,您在脚本标签中链接到它们并使用返回函数调用它们。

在您的模板标签中,您将执行以下操作:

<template>
<div>
 {{ temperatures }}
</div>
</template>
于 2020-11-25T07:10:00.813 回答