【问题标题】:v-img shows url instead of image in vuetifyv-img 在 vuetify 中显示 url 而不是图像
【发布时间】:2021-01-01 09:50:10
【问题描述】:

我正在使用 vuetify 2.3.10。我在这里面临的问题是 v-img 显示的是 image_url 而不是图像。我尝试了类似https://stackoverflow.com/a/53411531/12763413 的方法,但它对我不起作用。请帮我找出问题。

<template>
  <v-container fluid grid-list-lg>
    <v-card flat>
     <v-data-table 
       :headers="headers"
       :items="users"
       v-model="users"
       :sort-by="['full_name']"
       class="elevation-1"
     >
     <template slot="items" slot-scope="props">
       <td><v-img class="user-image" :src='props.item.image_url'/></td>
       <td class="full-name">{{ props.item.full_name }}</td>
     </template>
    </v-data-table>
   </v-card>
  </v-container>
</template>



<script>

 export default {
  props: ['users'],
  data: () => ({
    headers: [
      { text: '', value: 'image_url', sortable: false },
      { text: 'Name', value: 'full_name', sortable: false  }
    ]
  })
 };
</script>

【问题讨论】:

  • 您使用的是什么版本的 Vuetify?在当前版本中没有“项目”插槽 - 只有“项目”。你应该将该插槽的内容包装到&lt;tr&gt;&lt;/tr&gt;
  • @MichalLevý 我正在使用 vuetify 版本 2.3.10

标签: vue.js vuetify.js


【解决方案1】:

问题不在v-img 中,而是在您对v-data-table 的使用中 - 您正在使用不存在的插槽items(应该是item)所以v-data-table 忽略了您的插槽内容和渲染内容users 数据原样...这就是为什么你看到的是 url 而不是图片

您还应该将内容 item 插槽包装到 &lt;tr&gt;&lt;/tr&gt;

<template>
  <v-container fluid grid-list-lg>
    <v-card flat>
     <v-data-table 
       :headers="headers"
       :items="users"
       v-model="users"
       :sort-by="['full_name']"
       class="elevation-1"
     >
     <template slot="item" slot-scope="props">
       <tr>
         <td><v-img class="user-image" :src='props.item.image_url'/></td>
         <td class="full-name">{{ props.item.full_name }}</td>
       </tr>
     </template>
    </v-data-table>
   </v-card>
  </v-container>
</template>

【讨论】:

  • 查看固定模板
  • 非常感谢。
猜你喜欢
  • 2019-09-16
  • 2020-07-31
  • 2020-06-22
  • 1970-01-01
  • 1970-01-01
  • 2020-01-11
  • 2021-12-03
  • 2020-11-05
  • 2019-02-05
相关资源
最近更新 更多