Reputation: 334
I am trying to load images from the public folder in the vue components. The asset helper doesn't work in vue , so I need to use the format
<img :src="'img/ic_add-sm.svg'" >
But instead of looking for the images in the public folder , vue is appending the current URL to the image path. For example , if the url is www.example.com/posts
it adds www.example.com/posts/img/ic_add-sm.svg instead of www.example.com/img/ic_add-sm.svg
Upvotes: 13
Views: 31948
Reputation: 177
Just import the image from the public folder and use it as src.
<template>
<div>
<img :src="src" alt="message placeholder image" class="w-full object-cover">
</div>
</template>
<script setup>
import src from '/public/images/illustrations/messagenotselected.svg'
</script>
Upvotes: 0
Reputation: 61
At first bind the value of image source
<img :src="getPhoto() + variableName" />
Then create the function under your methods section and simply return the directory location, that's all.
getPhoto(){
return 'images/';
}
Upvotes: 0
Reputation: 376
Add a forward slash to the beginning of your image path.
<img :src="'/img/ic_add-sm.svg'">
Since you don't appear to be doing anything special you should be able to just use
<img src="/img/ic_add-sm.svg">
Upvotes: 35