对象上的 Nuxt 内容过滤
Nuxt Content Filtering on an object
我对如何在对象上执行 Nuxt Content where() 有一些疑问。我的意思是考虑以下 url:
www.mysite.com/blog/tag/tag-slug-here
在此页面上,我需要按该标签块过滤所有文章。现在我的.md结构如下:
---
layout: documentation
title: Post Title
date: 2016-06-14T15:24:30.719Z
date_updated: ''
tags:
- retainer
- clients
---
...
现在我注意到了以下几点:
In order to filter in objects and array you need to enable nestedProperties, see configuration.
所以在我的 nuxt 配置中我添加了:
content: {
nestedProperties: ['tags']
},
然而这似乎也不起作用。
我的搜索码:
const articles = await $content()
.where({ tags: params.slug })
.only(['title', 'description', 'thumbnail', 'slug', 'author', 'date'])
.sortBy('date', 'desc')
.limit(5)
.skip((route.query.page || 1) * 5)
.fetch()
我不确定我是否误解了文档或搜索,但如果有人有任何想法,那就太棒了!
找到我的答案:
https://github.com/nuxtlabs/demo-blog-nuxt-content/blob/master/pages/blog/tag/_tag.vue
这个文件是如何进行标签搜索的一个很好的例子。
我对如何在对象上执行 Nuxt Content where() 有一些疑问。我的意思是考虑以下 url:
www.mysite.com/blog/tag/tag-slug-here
在此页面上,我需要按该标签块过滤所有文章。现在我的.md结构如下:
---
layout: documentation
title: Post Title
date: 2016-06-14T15:24:30.719Z
date_updated: ''
tags:
- retainer
- clients
---
...
现在我注意到了以下几点:
In order to filter in objects and array you need to enable nestedProperties, see configuration.
所以在我的 nuxt 配置中我添加了:
content: {
nestedProperties: ['tags']
},
然而这似乎也不起作用。
我的搜索码:
const articles = await $content()
.where({ tags: params.slug })
.only(['title', 'description', 'thumbnail', 'slug', 'author', 'date'])
.sortBy('date', 'desc')
.limit(5)
.skip((route.query.page || 1) * 5)
.fetch()
我不确定我是否误解了文档或搜索,但如果有人有任何想法,那就太棒了!
找到我的答案: https://github.com/nuxtlabs/demo-blog-nuxt-content/blob/master/pages/blog/tag/_tag.vue
这个文件是如何进行标签搜索的一个很好的例子。