Element UI table表格中的单元格的数据过多时,显示规定的字符数

效果

在这里插入图片描述
在这里插入图片描述
要实现的效果如上图,单元格的数据过多时,规定只显示前5个字符,剩余的用 … 显示,另外添加一个小图标,点击图标弹出Dialog对话框,显示全部的单元格的数据

代码

单元格部分代码,直接判断单元格数据的字符长度

<el-table-column prop="motto" label="签名" align="center">
	<template slot-scope="scope">
    	{{scope.row.motto.length > 5 ? scope.row.motto.slice(0, 5) + "..." : scope.row.motto}}
        <i class="el-icon-copy-document icon"
           @click="showDialog(scope.row)"
        ></i>
    </template>
</el-table-column>

Dialog对话框

<el-dialog :visible.sync="dialogVisible" width="30%">
	<span slot="title">
       	<i class="el-icon-edit"></i>
        <span>签名</span>
    </span>
    {{ data }}
</el-dialog>

methods方法,把单元格的数据存在data中,在dialog中显示

showDialog(row) {
     this.dialogVisible = true;
     this.data = row.motto;
},
Vue Element UI 中,可以使用 `el-table-column` 的 `formatter` 属性来将日期类型的单元格转换为文本显示格式。`formatter` 属性接收一个函数,该函数可以自定义单元格显示内容。 以下是一个示例代码,展示了如何将日期类型的单元格转换为文本显示格式: ```html <template> <el-table :data="tableData" style="width: 100%"> <el-table-column prop="date" label="日期" :formatter="formatDate"></el-table-column> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="address" label="地址"></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [ { date: new Date(), name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' } ] }; }, methods: { formatDate(row, column) { const date = new Date(row.date); const year = date.getFullYear(); const month = ('0' + (date.getMonth() + 1)).slice(-2); const day = ('0' + date.getDate()).slice(-2); return `${year}-${month}-${day}`; } } }; </script> ``` 在这个示例中,`el-table` 组件绑定了 `tableData` 数据源。`el-table-column` 组件的 `prop` 属性指定了要显示数据字段,`label` 属性指定了列的标题。`el-table-column` 组件的 `formatter` 属性绑定了一个名为 `formatDate` 的方法,该方法用于格式化日期。 `formatDate` 方法接收两个参数:`row` 和 `column`。`row` 参数表示当前行的数据,`column` 参数表示当前列的配置。`formatDate` 方法中使用 `Date` 对象来格式化日期,并返回格式化后的字符串。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值