Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 613
user1592380 Avatar asked Jan 03 '19 17:01

user1592380


2 Answers

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

  src: '/52lv.PNG'
like image 123
ryeMoss Avatar answered Nov 03 '22 05:11

ryeMoss


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"/>
like image 27
Non404 Avatar answered Nov 03 '22 05:11

Non404