【问题标题】:Recover content from strapi using nuxtjs api使用 nuxtjs api 从strapi 中恢复内容
【发布时间】:2021-06-23 07:00:00
【问题描述】:

系统信息

  • Strapi 版本3.
  • 操作系统:MacOs Big Sur
  • 数据库:MariaDB
  • 节点版本:v14.17.0
  • NPM 版本:6.14.13
  • 纱线版本​​:1.22.5

大家好,我很难在 Nuxtjs API 中恢复 Strapi 表中的内容。
我想恢复以下位置的内容:location_id: 49 这是桌子:

[
  {
    id: 2,
    title: 'Legal notice',
    description: 'Hello',
    date: '2021-06-01',
    locale: 'fr-FR',
    created_at: '2021-06-21T20:27:23.000Z',
    updated_at: '2021-06-22T13:07:14.000Z',
    location: {
      id: 2,
      name: 'toto',
      location_id: 49,
      locale: 'fr-FR',
      created_at: '2021-06-21T20:30:31.000Z',
      updated_at: '2021-06-21T20:33:44.000Z'
    },
    localizations: [ [Object] ]
  },
  {
    id: 4,
    title: 'Test cell',
    description: 'csdcmsdml',
    date: '2021-06-06',
    locale: 'fr-FR',
    created_at: '2021-06-22T14:10:29.000Z',
    updated_at: '2021-06-22T14:10:29.000Z',
    location: null,
    localizations: [ [Object] ]
  }
]

【问题讨论】:

    标签: nuxt.js strapi


    【解决方案1】:

    您想提取第一个对象,对吗?
    假设我们的数组名为array,这样就可以了。

    this.array.filter(element => element.location?.location_id === 49)
    

    ?. 在这里很有用,因为 location: null 的情况,否则会引发错误。
    它叫做optional chaining

    【讨论】:

      【解决方案2】:

      我想恢复我写的所有语言的描述,我需要根据位置恢复描述的内容

      这是我在strapi上的内容类型的捕获:

      我有 4 个字段,我需要描述和位置。 这是我在 nuxtjs 中的要求:

      async asyncData({ app, i18n, $md }: any) {  
             const data = await app.$strapi.find('legal-notices', {
            _locale: i18n.localeProperties.iso })
      

      实际上我有英文和法文的描述内容,但它与位置无关,这是我的问题。

      感谢您的关注和帮助。

      【讨论】:

        猜你喜欢
        • 2021-01-27
        • 1970-01-01
        • 1970-01-01
        • 2023-01-28
        • 1970-01-01
        • 2019-11-13
        • 1970-01-01
        • 2010-11-21
        • 1970-01-01
        相关资源
        最近更新 更多