0
votes

I am trying to display images in a Vuetify data table column, but the image is not displaying in the desired slot, and only shows the URL of the image, e.g. "9384053.jpg". How do I display an image using slots in Vuetify?

Segment is an array containing image URLs such as 93034.jpg, 9348903.jpg etc. I am trying to display the first image only e.g. Segment[0] with a sample output of 846454.jpg.

<v-card>
  <v-card-title>
    Animals
    <v-spacer></v-spacer>
  </v-card-title>
  <v-data-table
    :headers="headers"
    :items="entries"
    :items-per-page="12"
    class="elevation-3"
    :multi-sort="true"
    mobile-breakpoint
    :search="search"
  >

    <template v-slot:item.Image="{ item }">
      <img :src="require(`${item.Image}`)" style="width: 50px; height: 50px" />
    </template>
  </v-data-table>
</v-card>

Here is the script file

<script>
import firebase from '../firebaseConfig';
const db = firebase.database().ref('/');

export default {
  name: 'Animals',
  data: () => ({
    search: '',
    entries: [],
    headers: [
      { text: 'ID', value: 'ID' },
      { text: 'RFID', value: 'RFID' },
      { text: 'Image', value: 'Segment[0]' },
      { text: 'Age', value: 'Age Years' },
      { text: 'Weight', value: 'Weight' },
    ],
  }),
  methods: {
    readAnimals() {
      db.once('value', (snapshot) => {
        snapshot.forEach((doc) => {
          const dataRetrieve = doc.val();
          this.$data.entries.push({
            ID: dataRetrieve.ID,
            RFID: dataRetrieve.RFID,
            'Age Years': dataRetrieve['Age Years']
            Weight: dataRetrieve.Weight,
            Length_History: dataRetrieve['Length_History'],
            Length: dataRetrieve.Length,
            Tag: dataRetrieve.Tag,
            Head: dataRetrieve.Head,
            Segment: dataRetrieve.Segment,

          });
        });
        return this.$data.entries;
      }).catch((error) => {
        console.log('error getting documents', error);
      });
    },
 
  },
  mounted() {
    this.readAnimals();
  },
};
</script>
2

2 Answers

0
votes
  <template v-slot:item.Image="{ item }">
  <img :src="item.Image" style="width: 50px; height: 50px" />
 </template>

You should bind it this way I think.

0
votes

This seems to do the trick

<template v-slot:item.Segment[0]="{item}">
      <img :src="item.Segment[0]" style="width: 50px; height: 50px" />
</template>

https://imgur.com/a/LX7JKoy