vue表格数据进⾏格式化
tabletable
<el-table :data="tableData">
<el-table-column prop="number" label="份数" />
</el-table>
此时number字段内容只是⼀个阿拉伯数字,我想作⼀些转换:
1--->第⼀份
Table-column提供了⼀个⽅法
我给formatter属性绑定了转换⽅法toChinesNum
<el-table-column prop="number" label="份数" :formatter="toChinesNum"/>
接着只需在methods上定义toChinesNum⽅法:
toChinesNum(row,column){
let num=row[column.property] //row[column.property]获取字段内容
num = parseInt(num);
let changeNum = ['零', '⼀', '⼆', '三', '四', '五', '六', '七', '⼋', '九'];
let unit = ["", "⼗", "百", "千", "万"];
let getWan = (temp) => {
let strArr = String().split("").reverse();
let newNum = "";
for (var i = 0; i < strArr.length; i++) {
newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;    }
return newNum;
}
let overWan = Math.floor(num / 10000);
let noWan = num % 10000;
if (String().length < 4) noWan = "0" + noWan;
let chinanum=overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
return `第${chinanum}份`
},

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。