0

I have this Vue component inside resources/js/components in my laravel project, and I'm trying to reference a static image but I cant get it right.

I tried placing this image in my public/imgs path and tried the following code in my vue component but none worked:

<img src="imgs/sample.jpg">
<img :src="require('imgs/sample.jpg')">

I tried placing it at a different location - resources/imgs - but it didn't work as well:

<img src="../imgs/sample.jpg">
<img :src="require('../imgs/sample.jpg')">

What is the proper way of referencing this static image?

2
  • <img src="/imgs/sample.jpg"> ?? (If they are located in your /public/imgs/ folder) Commented Apr 19, 2020 at 13:04
  • 1
    got it. a whitespace in the actual folder name threw me off Commented Apr 19, 2020 at 13:14

2 Answers 2

2

The code i have posted above is actually the right way to reference images inside vue components

<img src="imgs/sample.jpg">

What I have gotten wrong was the name of the folder which included a whitespace. Instead of just "imgs", the folder name was "imgs "

Sign up to request clarification or add additional context in comments.

Comments

0

If is static image reference, You can refer images directly using '@'

Example:

<img src="@/assets/images/home.png"/>

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.