link959 link960 link961 link962 link963 link964 link965 link966 link967 link968 link969 link970 link971 link972 link973 link974 link975 link976 link977 link978 link979 link980 link981 link982 link983 link984 link985 link986 link987 link988 link989 link990 link991 link992 link993 link994 link995 link996 link997 link998 link999 link1000 link1001 link1002 link1003 link1004 link1005 link1006 link1007 link1008 link1009 link1010 link1011 link1012 link1013 link1014 link1015 link1016 link1017 link1018 link1019 link1020 link1021 link1022 link1023 link1024 link1025 link1026 link1027 link1028 link1029 link1030 link1031 link1032 link1033 link1034 link1035 link1036 link1037 link1038 link1039 link1040 link1041 link1042 link1043 link1044 link1045 link1046 link1047 link1048 link1049 link1050 link1051 link1052 link1053 link1054 link1055 link1056 link1057 link1058 link1059 link1060 link1061 link1062 link1063 link1064 link1065 link1066 link1067 link1068 link1069 link1070 link1071 link1072 link1073 link1074 link1075 link1076 link1077 link1078 link1079 link1080 link1081 link1082 link1083 link1084 link1085 link1086 link1087 link1088 link1089 link1090 link1091 link1092 link1093 link1094 link1095

[Vue.js] Cannot display images in Vuejs

I’ve set up a carousel using bootstrap-vue. The carousel-items are created dynamically using a for loop and an array. The array contains three objects with the following keys: id, caption, text and image path. So far, when able to display the caption and text but not the images. I checked the console and there was no error. Hence, when very confused. Below are my codes and screenshots of the problem

UPDATE: when trying to fix this problem for 2 days already, help is greatly needed!

This is my project structure

This are my codes

<template>
<div>
<b-carousel
id=”carousel-1”
v-model=”slide”
:interval=”10000”
controls
indicators
background=”#ababab”
style=”text-shadow: 1px 1px 2px #333;”
@sliding-start=”onSlideStart”
@sliding-end=”onSlideEnd”
\>
<b-carousel-slide
v-for=”item in carouselItems”
:key=”item.id”
:caption=”item.caption”
:text=”item.text”
:style=”{ ‘background-image’: ‘url(‘ + item.image + ‘)’ }”
\></b-carousel-slide>
</b-carousel>
</div>
</template>

<script>

export default {
data() {
return {
carouselItems: [
{
id: 1,
caption: “Memories”,
image: “@/assets/images/Homepage-min.jpg”,
text: “Memories(1)”
},
{
id: 2,
caption: “Memories”,
image: “@/assets/images/Homepage-min.jpg”,
text: “Memories(2)”
},
{
id: 3,
caption: “Memories”,
image: “@/assets/images/Homepage-min.jpg”,
text: “Memories(3)”
}
],
slide: 0,
sliding: null
};
},
methods: {
onSlideStart(slide) {
this.sliding = true;
},
onSlideEnd(slide) {
this.sliding = false;
}
}
};
</script>

Here is a screenshot:

Update I went to take a look at the networks tab to see if I specified the wrong image path. However, the image path was correct as the status code is 304. What seems to be the problem? Can anyone help?

Update: I’ve removed the style and replaced it with the following code

:img-src=”item.image”

After I save the changes and refresh, I can see an icon indicating that the browser could not load the images.

Update I’ve successfully rendered the images to the carousel-slide. Apparently, “require” is needed if the image path is relative. I’ve updated this portion of my code to the following

data() {
return {
carouselItems: [
{
id: 1,
caption: “Memories”,
image: require(“@/assets/images/Homepage-min.jpg”),
text: “Memories(1)”
},
{
id: 2,
caption: “Memories”,
image: require(“@/assets/images/Homepage-min.jpg”),
text: “Memories(2)”
},
{
id: 3,
caption: “Memories”,
image: require(“@/assets/images/Homepage-min.jpg”),
text: “Memories(3)”
}
],
slide: 0,
sliding: null
};
},

Update However, now I face another problem, the image does not fit the entire height of the screen when in mobile mode. it to be responsive. Here is a screen shot of my problem

Update 7/5/2019 when still trying to fix this issue, can anyone help me with the CSS?

Solution :

Try using img-src=”https://xxxxx" instead of changing the style. You should get something like that in the code:

<b-carousel-slide
v-for=”item in carouselItems”
:key=”item.id”
:caption=”item.caption”
:text=”item.text”
:img-src=item.image
\></b-carousel-slide>

Or you can just use an actual img tag inside the <b-carousel-slide>:

<b-carousel-slide>
<img
slot=”img”
class=”d-block img-fluid w-100”
width=”1024”
height=”480”
src=”https://xxxxxx"
alt=”image slot”
\>
</b-carousel-slide>

You should also check the pictures ‘path’ since webpack adds a unique-id automatically to each image and can sometimes be troublesome in certain cases, just check that the webpack config is working on the images.