目标结果是这样滴
将后台给过来的字符串进行处理,处理后的字符串赋值到input框里。
// 千位符显示
comdify(n){
debugger
if(!n) return n;
let str = n.split('.');
let re = /\d{1,3}(?=(\d{3})+$)/g;
let n1 = str[0].replace(re, "$&,");
return str.length > 1 && str[1] ? `${n1}.${str[1]}` : `${n1}.00`;
},
delcommafy(num){
debugger
if(!num) return num;
num = parseFloat(num).toFixed(2)
num = num.toString();
num = num.replace(/,/gi, '');
return num;
},
然后在调接口返回的时候进行处理
getMessage(value).then((response) => {
this.form = response.data;
this.form.budgetTotalAmount = this.form.budgetTotalAmount == ''?'':this.comdify(this.delcommafy(this.form.budgetTotalAmount));
这样字段已经变为千位符显示啦!
如有帮助,点个赞再走呗!