0

我正在使用带有 Gridsome 的网站,并使用降价文件向网站提供内容。

我对降价的经验很少。虽然我并不真正了解 md 文件是如何工作的,但我设法通过一些教程让它工作,直到我开始将数组添加到 md 文件中,见下文。

content/home/index.md

---
metaTitle: this is the meta title tag
metaDescription: metadescription
someArray: [alpha, beta, delta] //I tried adding an array like this and it worked fine
imgArray: [{url: "someurl", alt: "some alt", caption: "some caption}, {url: "someurl", alt: "some alt", caption: "some caption}] //this did not work and caused an error
---

我的问题是是否可以在降价文件中添加对象数组?如果是,我该怎么写?非常感谢!

4

1 回答 1

2

在您的 YAML 中,该数组无效,因为它在some caption.


您描述的元数据部分是YAML frontmatter,它并不特定于 Gridsome 或 Vue。

是的,YAML 中允许对象数组作为逗号分隔的对象:

imgArray2: [
 {url: "someurl", alt: "some alt", caption: "some caption"},
 {url: "someurl", alt: "some alt", caption: "some caption"}
]

演示

...或作为列表,其中每个元素都从带有连字符前缀的新行开始:

imgArray:
 - {url: "someurl", alt: "some alt", caption: "some caption"}
 - {url: "someurl", alt: "some alt", caption: "some caption"}

演示

于 2020-05-04T06:58:39.130 回答