11

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?

2 Answers 2

22

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

  src: '/52lv.PNG'
Sign up to request clarification or add additional context in comments.

Comments

3

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"/>

1 Comment

Alternative you can just <img :src="require(`~/assets/img/${image}.jpg`)" /> as shown in the documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.