How can I insert an image on one row of my table? I have tried to put v-if in my loop through the columns but I cannot get it right. I am pretty new to quasar so I might confuse things. My idea was to use the v-if for checking if the column name is ‘Image’ insert an image. And only in that column
My columns are Name, Age and Image
Here is my code:
JavaScript
x
20
20
1
<template v-slot:body="props">
2
<div class="row-spacing"></div>
3
<q-tr
4
:props="props"
5
:class="tableFormat(props.row)"
6
@click="onRowClick($event, props.row)"
7
>
8
<q-td
9
class="td-my"
10
v-for="col in props.cols"
11
:key="col.name"
12
:props="props"
13
>{{ col.value }}
14
<div v-if="col.name === 'Image'">
15
<img class="profile-img" :src="profileimg[0].url" />
16
</div>
17
</q-td>
18
</q-tr>
19
</template>
20
Advertisement
Answer
Instead of profile image URL, you can use the props variable.
JavaScript
1
17
17
1
<template v-slot:body="props">
2
<q-tr :props="props">
3
<q-td
4
v-for="col in props.cols"
5
:key="col.name"
6
:props="props"
7
>
8
<span v-if="col.name !='Image'" >
9
{{ col.value }}</span>
10
11
<q-avatar v-if="col.name =='Image'" size="100px" class="shadow-10">
12
<img :src="props.row.image">
13
</q-avatar>
14
</q-td>
15
</q-tr>
16
</template>
17
You can refer the following codepen.