vue iview table Tooltip内容过多闪屏解决

vue的项目,框架是iview

 客户反应,指令描述的内容有几百个字,鼠标悬浮,浏览器开始闪烁

解决思路是加宽度限制,滚动,

后面发现像是transfer属性的bug,触碰浏览器底部,距离不够造成

做一个全局封装

在src/system/utils/  新建一个system.js文件

// 封装表格tooltip闪屏的处理  参数是 render: (h, params) => {}   例: content = params.row.original_info 

const renderTooltip = (h, params, content) => {

  const isTopPlacement = [0, 1, 2, 3].includes(params.row._index);

  const contentStyle = {

    whiteSpace: "normal",

    wordWrap: "break-word",

    maxHeight: "150px",

    overflow: "auto"

  };

  const tooltipProps = {

    props: {

      placement: isTopPlacement ? "bottom" : "top",

      transfer: isTopPlacement ? true : false

    },

    style: {

      width: "100%"

    }

  };

  let tooltipContent = null;

  if (content) {

    tooltipContent = [

      h("div", {

        style: {

          overflow: "hidden",

          textOverflow: "ellipsis",

          whiteSpace: "nowrap"

        }

      }, content),

      h("div", {

        slot: "content",

        style: contentStyle

      }, content)

    ];

  }

  return h("div", {}, [

    tooltipContent && h("Tooltip", tooltipProps, tooltipContent)

  ]);

}

export default {

  renderTooltip,

}


 

在src/util/   新建一个index.js文件

import systemUtil from '@/system/utils/system'

export default {

  $renderTooltip: systemUtil.renderTooltip  // 封装表格tooltip闪屏的处理 

}

main.js中导入

import util from '@/util/index'

Vue.prototype.$util = util // 将公共方法挂在到vue原型链上

在页面引入

 

{

            title: '指令描述', key: 'instructionDesc', align: 'center', minWidth: 120, ellipsis: true, tooltip: true,

            render: function (h, params) {

              return ths.$util.$renderTooltip(h, params, params.row.instructionDesc)

            }

          },

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码老祖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值