You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vuetify中v-data-table列模板内v-tooltip的实现方案咨询

在v-data-table列模板中添加v-tooltip的可行方案

直接在列模板内部嵌套v-tooltip组件即可解决报错问题,核心是把tooltip的激活逻辑绑定到列内的内容元素上,而非用activator结构包裹整个列模板。

针对"news"字段(对应title2列)的修改代码:

<template #item.title2="{ item }">
  <div class="ellipsis news">
    <v-tooltip bottom>
      <template #activator="{ on }">
        <a
          target="_blank"
          v-if="item.file !== ''"
          class="links1"
          :href="item.file"
          v-on="on"
        >
          <span style="color:white"> {{ item.title }} </span>
        </a>
        <!-- 处理file为空的情况,确保tooltip能正常触发 -->
        <span v-else v-on="on">{{ item.title }}</span>
      </template>
      <!-- 替换为你需要的news字段提示文本,比如完整内容 -->
      <span>{{ item.title }}</span>
    </v-tooltip>
  </div>
</template>

针对"actors"字段的实现示例:

假设actors对应的列模板是#item.actors,代码如下:

<template #item.actors="{ item }">
  <div class="ellipsis actors">
    <v-tooltip bottom>
      <template #activator="{ on }">
        <span v-on="on">{{ item.actors }}</span>
      </template>
      <!-- 替换为你需要的actors字段提示文本 -->
      <span>{{ item.actors }}</span>
    </v-tooltip>
  </div>
</template>

关键注意点:

  • 必须将v-tooltip嵌套在列模板的根元素内部,不能放在列模板外层,否则会破坏v-data-table的列渲染结构。
  • 所有需要触发tooltip的元素都要绑定v-on="on",包括条件渲染的分支,避免出现tooltip无法触发的情况。
  • 可通过修改v-tooltip的位置属性(如bottom/top/left/right)调整提示框的显示方向。

内容的提问来源于stack exchange,提问作者Quentin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 09:40:31