user1592380
user1592380

Reputation: 36337

Nuxt: displaying local image from static folder

enter image description here

I'm getting started with nuxt. My static folder is in the screenshot. I've been trying to follow https://nuxtjs.org/guide/assets/#static

I've got a vuetify carousel component that was working fine with urls as the src. Now I want to try to serve local static files. I tried:

    <template>
  <v-carousel>
    <v-carousel-item v-for="(item,i) in items" :key="i" :src="item.src"></v-carousel-item>
  </v-carousel>
</template>


    <script>

export default {
  data () {
    return {
      items: [
        {
          src: '/static/52lv.PNG'
        },
        {
          src: 'https://cdn.vuetifyjs.com/images/carousel/sky.jpg'
        },
        {
          src: 'https://cdn.vuetifyjs.com/images/carousel/bird.jpg'
        },
        {
          src: 'https://cdn.vuetifyjs.com/images/carousel/planet.jpg'
        }
      ]
    }
  }
}
</script>

but now when I run the dev server I get a blank screen for that image of the carousel . The other images with urls work fine.

Inspecting the blank element in the browser, I see:

enter image description here

How can I display this image?

Upvotes: 11

Views: 25417

Answers (2)

Non404
Non404

Reputation: 1293

In addition to this question, if we would have it in '~assets/images/521v.PNG' ?

Instead of doing this

 export default {   data () {
     return {
       items: [
         {
           src: '/static/52lv.PNG'
         },

Do this

   src: `${require(`~assets/images/521v.PNG`)}`

and you would use it like this:

  <img :src="items.src"/>

Upvotes: 3

ryeMoss
ryeMoss

Reputation: 4343

You don't need to specify the static folder, you should simply do:

  src: '/52lv.PNG'

Upvotes: 22

Related Questions