DEV Community

loading...
Cover image for How to pass dynamic image url in nuxt project . Ultimate Guide .

How to pass dynamic image url in nuxt project . Ultimate Guide .

dimer191996 profile image Dimer BWimBA ・1 min read

As the src properties will replaced by Webpack, you could do require function like this

<templae>
  <div>
    <img :src="imageUrl">
  </div>
</template>

<script>
export default {
  props: {
    imageUrl: {
      type: String,
      default: ''
    }
  }
}
</script>
Enter fullscreen mode Exit fullscreen mode

*ParentComponent.vue

<template>
  <ChildComponentExample :image-url="require('~/assets/myimage.png')" />
</template>
Enter fullscreen mode Exit fullscreen mode

This blog post explains how this works .:) Happy Code :)

Discussion (0)

pic
Editor guide