实现同样的需求还有另外3种方法
1、直接在页面中的插值表达式中使用Number方法:{{Number(需要处理的价格).toFixed(2)}
或者 通过管道符 |
调用 :{{需要处理的价格 | tofixed}}
2、在methods对象中定义方法,在插值表达式中调用
methods: {
tofixed(num) {
return Number(num).toFixed(2)
}
}
{{tofixed()}}
3、使用computed计算属性
computed:{
tofixed(){
return Number(需要处理的价格).toFixed(2)
}
}