I am currently working with an array of JSON objects that I need to import onto a webpage. The process involves iterating through the data and passing the objects as a prop to a component. One of the attributes within the JSON data is a relative path for an image located in my /assets/ folder.
For example, the JSON structure:
[
{
"title":"val1",
"img": "~/assets/image1.jpg",
"text":"Lorem ipsum dolor sit amet"
},
{
"title": "val2",
"img": "~/assets/image2.jpg",
"text":"Lorem ipsum dolor sit amet"
},
{
"title": "val3",
"img": "~/assets/image3.jpg",
"text":"Lorem ipsum dolor sit amet"
}
]
I am using a component from the Vue library (bootstrap-vue) that has an "img-src" directive for displaying images. However, when passing the prop with the image path to this directive, I am encountering a malformed path and a resulting 404 error.
Here is an example of usage:
<div>
<b-card :img-src="data.img"></b-card>
</div>
<script>
export default {
props: {
data: {
title: String,
img: String,
text: String
}
}
}
</script>
The requested URL for the image asset appears as http://localhost:3000/~/assets/image1.jpg. However, if I directly provide a static string path to the directive:
<div>
<b-card img-src="~/assets/image1.jpg"></b-card>
</div>
The image loads correctly with the URL for the asset being http://localhost:3000/_nuxt/assets/image1.jpg
I am seeking assistance in understanding what might be causing this issue.