引用:
<el-input v-model="dataObj.value" />
<span> ¥{{fmoney(dataObj.value)}} </span>
...
import fmoney in '../fmoney.js'
...
methods:{
fmoney,
...
getList(){
},
}
公共js文件:
export function fmoney(a, b) {
if(a==''||a=='undefined'||a==null)
{
return '--'
}
var c = "number" == typeof b && b > 0 && 20 >= b ? b : 2
a = parseFloat((a + "").replace(/[^\d.-]/g, "")).toFixed(c) + ""
for (var d = a.split(".")[0].split("").reverse(), e = a.split(".")[1], f = "", g = 0; g < d.length; g++) f += d[g] + ((g + 1) % 3 == 0 && g + 1 != d.length ? "," : "")
var re = f.split("").reverse().join("") + "." + e
if(re.substr(0, 2) == '-,'){
return re.replace(",","")
} else {
return re
}
}
效果: