verysu 设计模式 设计模式 响应式编程 百度开发平台 codeforces leetcode usfca

导航

vue table 合并单元格 合计 字符串转数值 数字input中英文导致值失效 转化column值

<el-table
border
show-summary //显示合计
:summary-method="yearEvalDetaSum"//合计计算方法
:span-method="arraySpanMethod2"
// 合并相同name单元格
arraySpanMethod1({ row, column, rowIndex, columnIndex }) {
},
//计算合计
yearEvalSum(params) {
const { columns, data } = params;
const sums = [];
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = "合计";
return;
}
if (column.property === "score") {
const values = data.map((item) => item[column.property]);
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
sums[index] += "";
} else if (column.property === "scoreExam") {
const values = data.map((item) => item[column.property]);
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
sums[index] = sums[index].toFixed(2) + "";
} else {
sums[index] = "";
}
});
return sums;
},
//字符串转数值
Number(item.dayScoreExam)

数字input中英文导致值失效
oninput="this.value=this.value.replace(/[^\d]/g,'');"
@blur="yearChange"
yearChange(e) {
this.dataForm.year = e.target.value;
}
转化tabledata column枚举值
 :formatter="setwarType"
setwarType(row, column){
switch (row.type) {
case "1":
return "行政处罚";
default:
return "";
}
},

posted on 2021-09-15 23:45  泳之  阅读(273)  评论(0编辑  收藏  举报

我是谁? 回答错误