Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass through prop containing image path in Vue?

I am trying to display an image in Vue template using a prop that i passed through in my App.vue file.

App.vue:

<Header image='../assets/logo.png' />

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Header.vue:

<template>
  <div class="div-box">
    <img :src={image} alt="Vue logo" />
  </div>
</template>

<script>
export default {
  name: "Header",
  props: ["image"],
};
</script> 

Thanks in advance!

>Solution :

You have to explicitly load the image "module":

<Header :image="require('../assets/logo.png')" />

vue-loader does this automatically for you for things like <img>, but if you’ve made your own component then you need to do it yourself.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading