1.时间戳转化时分秒
filters: {
//时间戳转化时分秒
formatDate: function (value) {
let date = new Date(value);
let y = date.getFullYear();
let MM = date.getMonth() + 1;
MM = MM < 10 ? ('0' + MM) : MM;
let d = date.getDate();
d = d < 10 ? ('0' + d) : d;
let h = date.getHours();
h = h < 10 ? ('0' + h) : h;
let m = date.getMinutes();
m = m < 10 ? ('0' + m) : m;
let s = date.getSeconds();
s = s < 10 ? ('0' + s) : s;
return y + '-' + MM + '-' + d + " "+ h + ':'+m + ':'+s ;
}
},
使用方法
<el-form-item label="报价截止时间:">
<span>{{projectForm.provideProject.endtime|formatDate}}</span>
</el-form-item>
2.金额数字进行千分位格式化
filters: {
//数字,金额千分位
num_filter(val){
val =val.toLocaleString() // 3,000.5
if(val.indexOf(".")==-1){
val=val+".00"
}else if(val.charAt(val.indexOf(".")==val.length-2)){
val=val+"0" // //3,000.50
}
return val
}
},
使用方法
<el-col :span="12">
<el-form-item label="预算金额:">{{projectForm.provideProject.money | num_filter}元</el-form-item>
</el-col>
网友评论