首页 > 解决方案 > 无法使用 nuxt,js 在 Strapi 中读取未定义的属性“url”

问题描述

我得到无法读取未定义错误的属性“url”。我不明白为什么。当我将线路更改 <img :src="'api.example.com' + gallery.Main_picture.url"> 为例如{{ gallery.Title }} 一切正常时。我做错了什么?在控制台中,我看到了应有的整个响应。我将不胜感激,并提前感谢您。我将我的 api 域更改为 example.com

<template>
  <v-row no-gutters class="black--text">
    <v-col>
      <img :src="'api.example.com' + gallery.Main_picture.url">
    </v-col>
  </v-row>
</template>

<script>
export default {
  data () {
    return {
      gallery: {}
    }
  },
  async mounted () {
    this.gallery = await this.$strapi.$galleries.findOne(this.$route.params.id)
    console.log(this.gallery.Main_picture.url)
  }
}
</script>

标签: javascriptjsonvue.jsnuxt.jsstrapi

解决方案


试试这个:

<img :src="`//api.example.com${gallery.Main_picture.url}`">

推荐阅读