vue怎么实现element表格里表头信息提示功能?

需求

如图:在element表格操作一栏需要添加提示功能

实现效果

如图:鼠标浮上去弹出tips

解决方案

1、编写组件

promptMessage.vue文件里面实现

<template>
<!-- 处理element表格表头文字提示特别添加全局注册组件  -->
<div class="promt-message-tooltip">
    <el-tooltip effect="light" placement="left">
        <div slot="content">
            <p v-for="item in messages" :key="item">
                {{item}}
            </p>
        </div>
        <i class="el-icon-question" class="tips-icon"></i>
    </el-tooltip>
</div>
</template>

<script>
export default {
  props: ['messages']
}
</script>
<style lang="scss">
.promt-message-tooltip {
  .tips-icon {
    color:#409eff;
    margin-left:5px;
    font-size:14px;
  }
}
</style>

2、开发插件

index.js文件里面实现

import promptMessage from './promptMessage.vue'

export default {
  install: (Vue) => {
    Vue.component('promptMessage', promptMessage)
  }
}

3、使用插件

main.js文件里面实现

import promptMessage from '@/components/promptMessage/index.js'

Vue.use(promptMessage)

4、业务代码实现

<template>
<el-table tooltip-effect="light" :data="dataList" border >
  <el-table-column label="操作" :render-header="renderHeader">
    <template slot-scope="scope">删除</template>
  </el-table-column>
</el-table>
</template>

<script>
export default {
  methods: {
    // render 事件
    renderHeader (h, { column }) {
      return h(
        'div', {
          style: 'display:flex;margin:auto;'
        },
        [
          h('span', column.label),
          // 直接用组件就完事了
          h('prompt-message', {
            props: { messages: ['kaimo需要的tips!'] }
          })
        ]
      )
    }
  }
}
</script>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

凯小默

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

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

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

打赏作者

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

抵扣说明:

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

余额充值