定义一个methods方法
// 千分位匹配价钱
isMoney(val) {
if (typeof val === "number") {
return val.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
}
},
请求到数据 遍历数据处理价钱做千分位计算
this.tableData = res.data.data.items;
// console.log(this.tableData)
this.tableData.forEach(x => {
// 遍历数据每一项 如果值为number数据类型 表示为价钱金额 处理千分位
for (const key in x) {
if (typeof x[key] === "number") {
x[key] = this.isMoney(x[key]);
}
}
}