当跟随来自 v 按钮的链接时,Vuetify 工具提示显示在左上角

瓦茨拉夫·佩尔奇

在 Vuetify 中遇到了Tooltip 组件的奇怪行为我在 Vuetify 的DataTable 组件中使用了这个组件,我在其中一个数据列中使用了一个插槽,我在其中添加了 Vuetify 的Button 组件,然后我在该按钮中使用了 Tooltip 组件。

问题定义:

工具提示行为如下:

  • 当我将鼠标移到按钮上并等待时,工具提示正确显示。
  • 当我在显示工具提示时单击该按钮时,它会重定向到正确的页面,并且一切都按预期进行。
  • 当我在没有显示工具提示的情况下单击按钮时,它会重定向到正确的页面,但工具提示会显示在页面的左上角并卡住。
  • 当工具提示卡住时,我可以重定向到不同的页面,但工具提示仍在左上角。
  • 当工具提示卡住时,我可以返回带有表格的页面。如果我将鼠标移到最初用于重定向的按钮然后移开,工具提示就会消失。

附加信息:

我发现这种行为可能是由于在我的应用程序中,我已将此组件设置为通过以下方式保持活动状态

<keep-alive :include="['PrintHistory']">
  <router-view />
</keep-alive>

当我删除PrintHistory字符串时,它的行为符合预期。

我还发现当我将open-delay参数设置为更高的数字时,它会在左上角以更高的延迟显示工具提示。

无论我重定向到哪个页面,问题仍然存在。

整个组件的代码:

<template>
  <div>
    <v-layout style="width:100%;" justify-space-between class="mb-0">
        <h2>{{ $t('print_history.title') }}</h2>
    </v-layout>
    <v-card class="elevation-1 my-1 pt-1" v-resize="onResize">

      <v-layout style="text-align: right;">
        <v-spacer></v-spacer>
        <v-text-field
          v-model="search"
          append-icon="mdi-magnify"
          :label="$t('print_history.search')"
          class="ma-2"
        ></v-text-field>
      </v-layout>

      <v-data-table :headers="headers"
                    :items="rows"
                    :loading="loading"
                    :loading-text="$t('v_big_table.loading')"
                    :sort-by="'action_at'"
                    :sort-desc="true"
                    :search="search"
                    :page.sync="page"
                    @page-count="page_count = $event"
                    hide-default-footer
                    :items-per-page="computed_items_per_page">
        <template v-for="header in headers" v-slot:[`header.`+header.value]="{ header }">
          <span class="table_header" v-bind:key="`header_customization_`+header.value">{{ $t(header.text) }}</span>
        </template>
        <template v-slot:item.show_file="{ item }">
          <!-- The redirecting is not yet finished -->
          <v-btn :to="`/pdfjs-viewer`" icon small class="ma-0" color="primary">
            <v-tooltip top open-delay="600" :color="tooltip_bg_color">
              <template v-slot:activator="{ on, attrs }">
                    <v-icon
                      v-bind="attrs"
                      v-on="on">mdi-file-search-outline</v-icon>
              </template>
              <span class="tooltip">{{ $t('print_history.show_file') }} {{ item['path_to_file'].split("/")[item['path_to_file'].split("/").length-1] }}</span>
            </v-tooltip>
          </v-btn>
        </template>
      </v-data-table>
      <v-pagination
        v-model="page"
        :length="page_count"
        :total-visible="9"
      ></v-pagination>
    </v-card>
  </div>
</template>

<script>

/**
 * @typedef {Object} Sorter - stores information about column sorting
 * @property {string} field - unique name of the column to sort
 * @property {string} dir - direction of sorting: ascending ('asc'), descending ('desc')
 */

/**
 * @typedef {Object} Filter - stores information about column sorting
 * @property {string} field - unique name of the column to filter
 * @property {string} operator - operator defining the filter
 * @property {string} value - direction of sorting: ascending ('asc'), descending ('desc')
 * @property {string} color - color of the v-chip when the filter is shown
 */

import { utcTimeStamp, utcToLocal } from '../../../utils'

/**
 * Shows a history of printing arranged in a table with sorting and filtering capabilities.
 */
export default {
  name: "PrintHistory",
  data () {
    return {
      tooltip_bg_color: 'rgba(0,0,0,0.7)',
      err_msg: '',
      search: '',
      row_count: 0,
      total_row_count: 0,
      rows: [],
      rows_filtered: [],
      loading: true,
      page: 1,
      page_count: null,
      default_items_per_page: 13,
      window_size: {
        x: 0,
        y: 0
      },
      initial_sorters: [{field: 'action_at', dir: 'desc'}],
      headers: [
        {
          text: 'print_history.date_and_time',
          value: 'action_at',
          align: 'end'
        },
        {
          text: 'print_history.report_type',
          value: 'translated_report_type'
        },
        {
          text: 'print_history.user_id',
          value: 'user_id'
        },
        {
          text: 'print_history.user_name',
          value: 'user_name'
        },
        {
          text: 'print_history.state',
          value: 'translated_state'
        },
        {
          text: 'print_history.show_file',
          value: 'show_file',
          sortable: false,
        },
      ],
      last_update: null,
    }
  },
  computed: {
    computed_items_per_page() {
      return Math.max(Math.floor((this.window_size.y - 300)/48), 1)
    }
  },
  methods: {
    utcToLocal,
    /**
     * Loads data from database. Assigns loading error in case the data cannot be loaded.
     */
    loadData() {
      this.loading = true
      this.last_update = utcTimeStamp()
      let start_time = Date.now()
      this.$store.dispatch('getPrintHistory')
      .then((response) => {
        this.rows = this.transformData(response.data)
        this.row_count = this.rows.length
        this.total_row_count = response.data.total_row_count
        console.log("Total time:" + (Date.now() - start_time))
      })
      .catch(() => {
        this.err_msg = 'errors.error_loading_data'
        this.data = []
      })
      .finally(() => {
        this.loading = false
      })
    },
    /**
     * This will show file in a javascript PDF browser once implemented.
     * @param absolute_path absolute path to the file to be shown
     */
    showFile(absolute_path) {
      console.log(absolute_path)
    },
    /**
     * Processes data before saving them to rows.
     * @param {object[]} data_to_transform array of objects that should be processed
     * @return {object[]} array of objects that are formatted for the data table
     */
    transformData(data_to_transform) {
      let data_to_return = data_to_transform
      data_to_return.forEach((entry) => {
        entry['user_name'] = entry.user.name
        entry['path_to_file'] = entry.misc.path_to_file
        entry['action_at'] = this.$d(utcToLocal(entry.action_at), 'datetime')
        entry['translated_report_type'] = this.$t(`print_history.report_types.` + entry.report_type)
        entry['translated_state'] = this.$t(`print_history.states.` + entry.state)
      })
      return data_to_return
    },
    onResize() {
      this.window_size = {x: window.innerWidth, y: window.innerHeight}
    }
  },
  beforeMount() {
    this.loadData()
  },
  activated() {
    // check if the server has new data, refresh component data if true
    this.$store.dispatch('lastDataUpdate')
    .then((response) => {
      if (response.data > this.last_update) {
        this.loadData()
      }
    })
    // on error refresh anyway
    .catch(() => {
      this.loadData()
    })
  },
}
</script>

<style scoped>
.table_header {
  font-weight: bold;
  color: black;
}
</style>

response.data通过该loadData方法从数据库中检索的示例

[{
   action_at: "2021-01-20T13:03:39.528843",
   id: "1",
   inventory_id: "1",
   reporty_type: "my_report_type",
   state: "archived",
   misc: {
     path_to_file: '/some/path/to/file.pdf'
   },
   user: {
     name: "John Doe",
     id: "123456",
     roles: {role_1: true}
   },
   user_id: "123456"
 },
 {
   action_at: "2021-01-20T13:05:39.528843",
   id: "2",
   inventory_id: "1",
   reporty_type: "my_other_report_type",
   state: "moved_to_print",
   misc: {
     path_to_file: '/some/path/to/file2.pdf'
   },
   user: {
     name: "Jane Doe",
     id: "123457",
     roles: {role_1: true}
   },
   user_id: "123457"
 }]

问题:

此工具提示行为是错误还是我必须为其设置一些其他设置?是否有一些解决方法,以便即使组件保持活动状态它也能正常运行?

如果有一些额外的信息,请询问。

卡琳·C

似乎您有与此相同的问题:https : //github.com/vuetifyjs/vuetify/issues/2480但使用不同版本的 Vuetify。

按钮的工具提示属性有很多问题和请求,但现在解决方案可能类似于此修复程序:https : //github.com/vuetifyjs/vuetify/pull/2780

  1. show在数据中定义(如果你使用 v-model 作为工具提示,我认为它应该设置为 false)
  2. 将@click 事件添加到按钮,如下所示: @click="show = false"
  3. 对于工具提示,您有 2 个选项:添加v-if="show"v-model="show"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

当DropDownStyle为Simple时,ToolStripCombobox显示在屏幕的左上角

下拉菜单显示在右上角,单击时显示在左上角

从抽屉中调用listviewScreen时,左上角没有显示后退按钮

移除左上角的后退按钮

Image.file 未显示图像,链接出现在左上角并带有选择文件按钮

在点击时显示Google地图左上角的信息窗口?

在KDE Windows中,左上角的按钮是什么?

SwiftUI - 按钮在视图的左上角不起作用

当我切换到 RelativeLayout 时,我在设计中放置的所有内容都会显示在屏幕的左上角

在vuetify中,如何在禁用按钮时显示工具提示

以编程方式添加时左上角的 ConstraintLayout 视图

安装ubuntu时,左上角的白色小屏幕

Bootstrap 4徽章覆盖左上角,即使在折叠时也保持导航栏链接

从editext中删除左上角提示

在V-CALENDAR Vuetify Vuejs中显示来自Api的数据

在禁用按钮上显示Vuetify工具提示

检查自定义工具提示的左上角是否在范围内

如何在使用 4k 主 Linux Ubuntu 20 时修复高清外接显示器的屏幕重叠和左上角缩放?

显示器左上角的桌面

在链接按钮顶部显示工具提示

链接指向R中带有networkD3的forceNetwork中的左上角

如何在pinterest.com的左上角制作3行按钮?

按钮未出现在场景中而出现在左上角

在Sublime中,界面左上角的向左/向右箭头按钮有什么作用?

如何将共享按钮放置在游戏的左上角而不是视图上?

在标题前左上角的android工具栏中显示imageview

点击按钮添加编辑器时,summernote note-popover 出现在左上角

创建带框架的懒惰按钮时,这是在左上角创建的,为什么会发生这种情况?

当我在没有输入用户名和密码的情况下按下登录按钮时,浏览器的左上角显示这样的信息“无效信息”