javascript - 如何在 Vue.js 中有条件地显示工具提示?

标签 javascript html vue.js v-tooltip

我正在尝试有条件地显示 v-tooltip基于 bool 值。这是我目前拥有的:

<div v-for="predefinedContentItem in getPredefinedContentCategoryItems(category.id)"
  :class="['category-item-content-wrapper', { 'not-clickable': isMainDialogClosed}]"
  v-tooltip.right="getPredefinedContentItemMessage(predefinedContentItem)"
  slot="content"
  :key="predefinedContentItem.id"
  @click="onPredefinedContentItemClick(predefinedContentItem, category.id)">

我并不是要动态显示不同的工具提示文本。我想确定是否显示实际的工具提示。我尝试了以下三元组但没有成功:

<div v-for="predefinedContentItem in getPredefinedContentCategoryItems(category.id)"
  :class="['category-item-content-wrapper', { 'not-clickable': isMainDialogClosed}]"
  v-tooltip.right="isAutomotive ? getPredefinedContentItemMessage(predefinedContentItem) : null";
  slot="content"
  :key="predefinedContentItem.id"
  @click="onPredefinedContentItemClick(predefinedContentItem, category.id)">

最佳答案

您可以向 v-tooltip 传递一个带有额外选项的对象,并在指令中添加 show 属性,如下所示:

<div v-tooltip="{
  content: getPredefinedContentItemMessage(predefinedContentItem),
  show: isAutomotive,
  trigger: 'hover',
  placement: 'right',
}">

关于javascript - 如何在 Vue.js 中有条件地显示工具提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57616642/

相关文章:

javascript - 在 Vue 组件中使用 CSS 变量(作用域)

javascript - Vue js如何防止href默认行为更改URL名称

javascript - 连接 JQuery 变量

javascript - MaterializeCSS 图标不适用于 Angular 7 中的导航栏

html - 动态高度问题

javascript - 如何在不对特定行进行排序的情况下使 html 表可排序?

javascript - Bxslider切换幻灯片后暂停视频

javascript - 动态路由防止在 Next.js 中重定向到 404 页面

javascript - 隐藏 select2 多搜索框

vue.js - Electron-Vue 应用程序的状态存储在哪里?