0

I have a Vue component located at resources/js/modules/MyComponent.vue and inside it, I'm trying to use a local image as an src for the img tag, and the image is located at public/assets/myproj/image/myimage.png.

I've tried using the following :

<img src="@/assets/myproj/image/myimage.png"/>
<img src="require('assets/myproj/image/myimage.png')"/>
<img src="../../../public/assets/myproj/image/myimage.png"/>
<img src="/assets/myproj/image/myimage.png"/>

but none of them work...

I know this is a straightforward question but I hope someone can help me because I've been trying to find an answer for almost an hour now but I still can't figure it out.

2
  • 1
    Image src path should be accessible to your server clients. Commented Feb 9, 2021 at 19:20
  • okay nvm i got it, imported the image instead using relative path Commented Feb 9, 2021 at 19:24

1 Answer 1

1

If you want to use this in javascript you can do like this

<img :src='getImage(name)'/>

then you will need to import your image in your javascript code

getImage(name){
 return require(`@/assets/myproj/${name}`);
}
Sign up to request clarification or add additional context in comments.

Comments

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.