vue中的el-tooltip提示黑框遮擋問題
vue el-tooltip提示黑框遮擋
在用于文字過長提示的時(shí)候,如果輸入框?yàn)榭铡?/p>
就會(huì)出現(xiàn)黑框遮擋問題。
解決方法
例:
<el-table-column prop='Remark' :label='trInvoiceBatch.Remark.Name' show-overflow-tooltip v-if="!readOnly"> <template scope='scope'> <el-tooltip class="item" effect="dark" :content="scope.row.Remark" placement="top-start" :disabled="scope.row.Remark.length<5"> <el-input size='small' v-model='scope.row.Remark' @change='setRowStateType(scope.row)'></el-input> </el-tooltip> </template> </el-table-column>
使用 :disabled="scope.row.Remark.length<5" 來解決問題
貼上 el-tooltip 的詳細(xì)用法
el-tooltip的使用(根據(jù)條件控制顯示)
el-tooltip根據(jù)條件控制顯示
列表型
代碼如下:
<template> <div> <ul> <li v-for="(item, index) in listData" :key="item.id" class="item_box"> <el-tooltip effect="dark" :content="item.content" :popper-class="isShowTooltip ? 'hide-tooltip' : ''" > <p class="item"> <span @mouseenter.stop.prevent="onMouseOver(index)" @mouseleave.stop.prevent="isShowTooltip = true" :class="showMenuClass" >{{ item.content }}</span > </p> </el-tooltip> </li> </ul> </div> </template> <script> import { defineComponent, reactive, toRefs } from "vue"; import DataJS from "@/JSON/data.js"; import $ from "jquery"; export default defineComponent({ name: "page-five", setup() { const { DataJSON } = DataJS(); const state = reactive({ isShowTooltip: true, showMenuClass: "ref_" + Math.random().toString(7).substr(2), }); let timer = null; function onMouseOver(index) { state.isShowTooltip = true; let data = null; data = $(`.${state.showMenuClass}`)[index]; let parentWidth = data.parentNode.offsetWidth; let contentWidth = data.offsetWidth; clearTimeout(timer); timer = setTimeout(() => { if (contentWidth > parentWidth) { console.log(parentWidth, contentWidth); state.isShowTooltip = false; } }, 500); } return { ...toRefs(DataJSON), ...toRefs(state), onMouseOver, }; }, }); </script> <style> .item_box { height: 35px; width: 400px; list-style-type: none; } .item { width: 100%; display: inline-block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; } .hide-tooltip { visibility: hidden; } </style>
效果展示:
樹狀圖型
代碼如下:
<template> <div class="tree_box"> <el-tree :data="treeData"> <template #default="{ node }"> <el-tooltip effect="dark" :content="node.label" :popper-class="treeTooltip ? 'hide-tooltip' : ''" > <p class="tree_title" :class="showTreeClass + '-' + node.id"> <span @mouseenter.stop.prevent="ellipsis(node.id)" @mouseleave.stop.prevent="treeTooltip = true" >{{ node.label }}</span > </p> </el-tooltip> </template></el-tree > </div> </template> <script> import { defineComponent, reactive, toRefs } from "vue"; import TreeDataJS from "@/JSON/treeData.js"; import $ from "jquery"; export default defineComponent({ name: "page-five", setup() { const { TreeDataJSON } = TreeDataJS(); const state = reactive({ treeTooltip: true, showTreeClass: "ref_" + Math.random().toString(7).substr(2), }); // 樹eltoop let treeTimer = null; function ellipsis(index) { let treeDataHtml = null; treeDataHtml = $(`.${state.showTreeClass + "-" + index}`)[0]; let treeParentWidth = treeDataHtml.parentNode.offsetWidth; let treeContentWidth = treeDataHtml.offsetWidth; let treeLeft = treeDataHtml.offsetLeft; clearTimeout(treeTimer); treeTimer = setTimeout(() => { if (treeContentWidth + treeLeft + 4 > treeParentWidth) { state.treeTooltip = false; } }, 500); } return { ...toRefs(TreeDataJSON), ...toRefs(state), ellipsis, }; }, }); </script> <style> .tree_box { margin-top: 90px; width: 500px; } .tree_title { display: inline-block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .hide-tooltip { visibility: hidden; } </style> 片
效果展示:
注意:均要設(shè)置所設(shè)選擇器的樣式
.hide-tooltip { visibility: hidden; }
附JSON數(shù)據(jù)
// @/JSON/data.js import { reactive } from "vue"; export default function () { const state = reactive({ listData: [ { id: 1, content: "你真的無法想象我就像是住在一個(gè)魚缸", }, { id: 2, content: "魚缸旅館里該有的什么都有", }, { id: 3, content: "像一個(gè)小小的時(shí)空膠囊", }, { id: 4, content: "那些說愛我的人,都可以清楚地追蹤我,不像魚無視目光只有魚自己", }, { id: 5, content: "我努力做他們熱愛的我,我與陌生的自己竊竊私語,就像看到透明人一覽無遺", }, { id: 6, content: "我沒有退縮也沒有閃躲,當(dāng)我流淚也沒有人看穿,那些不愛我的人,也可以無謂地注視我,看我在魚缸里因無聊而崩潰", }, { id: 7, content: "我派無人飛機(jī)出去尋找,以為你會(huì)帶來救兵的訊號(hào)", }, { id: 8, content: "除了想你時(shí)吐出的氣泡,我在機(jī)場冰冷等待擁抱", }, { id: 9, content: "魚缸里沒有黑夜,我也失去了我的睡眠", }, { id: 10, content: "我忘了我是水里游蕩的王子,還是他已經(jīng)溺斃的愛人,還是他已經(jīng)溺斃的愛人", }, ], }); return { DataJSON: state, }; }
// @/JSON/treeData.js import { reactive } from "vue"; export default function () { const state = reactive({ treeData: [ { id:'1', label: "魚缸旅館", children: [ { id:'1-1', label: "你真的無法想象我就像是住在一個(gè)魚缸", children: [ { id:'1-2', label: "魚缸旅館里該有的什么都有", }, { id:'1-3', label: "像一個(gè)小小的時(shí)空膠囊", }, ], }, ], }, { id:'2', label: "那些說愛我的人,都可以清楚地追蹤我,不像魚無視目光只有魚自己", children: [ { id:'2-1', label: "我努力做他們熱愛的我,我與陌生的自己竊竊私語,就像看到透明人一覽無遺", children: [ { id:'21-1', label: "我沒有退縮也沒有閃躲,當(dāng)我流淚也沒有人看穿,那些不愛我的人,也可以無謂地注視我,看我在魚缸里因無聊而崩潰", }, { id:'2-1-2', label: "我派無人飛機(jī)出去尋找,以為你會(huì)帶來救兵的訊號(hào)", }, ], }, { id:'3', label: "除了想你時(shí)吐出的氣泡,我在機(jī)場冰冷等待擁抱", children: [ { id:'3-1', label: "魚缸里沒有黑夜,我也失去了我的睡眠", }, { id:'3-2', label: "我忘了我是水里游蕩的王子,還是他已經(jīng)溺斃的愛人,還是他已經(jīng)溺斃的愛人", }, ], }, ], }, ], }); return { TreeDataJSON: state, }; }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決vue中使用swiper插件問題及swiper在vue中的用法
Swiper是純javascript打造的滑動(dòng)特效插件,面向手機(jī)、平板電腦等移動(dòng)終端。這篇文章主要介紹了解決vue中使用swiper插件及swiper在vue中的用法,需要的朋友可以參考下2018-04-04vue3手動(dòng)設(shè)置滾動(dòng)條位置自動(dòng)定位功能
這篇文章介紹了vue3手動(dòng)設(shè)置滾動(dòng)條位置自動(dòng)定位功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-12-12使用vue3重構(gòu)拼圖游戲的實(shí)現(xiàn)示例
這篇文章主要介紹了使用vue3重構(gòu)拼圖游戲的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01VUE+axios+php實(shí)現(xiàn)圖片上傳
這篇文章主要為大家詳細(xì)介紹了VUE+axios+php實(shí)現(xiàn)圖片上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08Vue3+vite路由配置優(yōu)化(自動(dòng)化導(dǎo)入)
這篇文章主要介紹了Vue3+vite路由配置優(yōu)化(自動(dòng)化導(dǎo)入),需要的朋友可以參考下2023-09-09vue中echarts點(diǎn)擊事件點(diǎn)擊一次多次觸發(fā)問題
這篇文章主要介紹了vue中echarts點(diǎn)擊事件點(diǎn)擊一次多次觸發(fā)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06Vue+WebSocket頁面實(shí)時(shí)刷新長連接的實(shí)現(xiàn)
最近vue項(xiàng)目要做數(shù)據(jù)實(shí)時(shí)刷新,數(shù)據(jù)較大,會(huì)出現(xiàn)卡死情況,所以本文主要介紹了頁面實(shí)時(shí)刷新長連接,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06