I am using Vue and have a variable. If the variable has a value, I want to display an image (pic1). However, if the variable is empty, then I want to show another image (pic2).
Here's my code...
<template v-for="(item, index) in items">
<img v-if="item.var" v-bind:src="'/images/pic1'">
<img v-else v-bind:src="'/images/pic2'">
<img v-if="item.var.length > 0" v-bind:src="'/images/pic1.jpg'">
<img v-if="item.var.length == 0" v-bind:src="'/images/pic2.jpg'">
</template>
I have tried implementing two independent options:
I used v-else, but it didn't work as expected. It only displayed posts with item.var, while discarding those with empty item.var.
I also attempted using .length, but it didn't work at all.
Any suggestions on how to make this functionality work correctly?