基于element-ui的 ToolTip组件封装(使用vue)

       ToolTip是element提供展示鼠标 hover 时提示信息的一款组件 最近开发中正好有这样的需求 并且添加了超出显示省略并提示 话不多说上代码。

<template>
  <el-tooltip class="item" effect="dark" :content="title" :placement="direction" :disabled="disabled">
    <span> {{ handleTitle() }}</span>
  </el-tooltip>
</template>
<script>
export default {
  name: 'ToolTip',

  props: {
    title: {
      type: String,
      required: false
    },
    max: {
      type: Number,
      required: false,
      default: 10
    },
    direction: {
      type: String,
      required: false,
      default: 'top'
    }
  },
  data()
{
    return{
disabled="false"
}
},
  methods: {
    handleTitle() {
      if (this.title.length > this.max) {
        return this.title.slice(0, this.max) + '...'
      } else {
        disabled="true" //不超出是不显示
        return this.title
      }
    }
  }
}
</script>

组件的引入

<el-table-column label="客户名称" align="center" prop="customerName" width="150">
        <template slot-scope="scope">
          <ToolTip :title="scope.row.customerName" />
        </template>
      </el-table-column>
<script>
import ToolTip from '@/components/ToolTip'


export default {
  name: '',
  components: {

 ToolTip
}
},

实际效果

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值