【问题标题】:Nuxt Content Filtering on an object对象上的 Nuxt 内容过滤
【发布时间】:2021-05-28 00:27:34
【问题描述】:

对于如何在对象上执行 Nuxt Content where() 有点问题。我的意思是考虑以下网址:

www.mysite.com/blog/tag/tag-slug-here

在此页面上,我需要按该标签 slug 过滤所有文章。现在我的 .md 结构如下:

---
layout: documentation
title: Post Title
date: 2016-06-14T15:24:30.719Z
date_updated: ''
tags:
  - retainer
  - clients
---

...

现在我确实注意到了以下几点:

为了过滤对象和数组,您需要启用nestedProperties,请参阅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()

我不确定我是否误解了文档或搜索,但如果有人有任何很棒的想法!

【问题讨论】:

    标签: nuxt.js nuxt-content


    【解决方案1】:

    找到我的答案: https://github.com/nuxtlabs/demo-blog-nuxt-content/blob/master/pages/blog/tag/_tag.vue

    这个文件是如何进行标签搜索的一个很好的例子。

    【讨论】:

      猜你喜欢
      • 2020-01-02
      • 2020-07-30
      • 2016-08-09
      • 2023-03-18
      • 2017-05-17
      • 2018-09-07
      • 2022-11-27
      • 2012-07-11
      • 2021-11-10
      相关资源
      最近更新 更多