vue封装全局过滤器 保留两位小数

项目中需要金额及数量中保留两位小数思路如下

  • 封装全局过滤器
  • 使用toFixed(2) 方法 保留两位小数
    方法如下
// main.js 中写入
Vue.filter('rounding', (value) => {
  return value.toFixed(2);
})
// 使用
demo.vue 中使用
			<el-table-column label="采购金额" prop="amount" width="150">
	            <template slot-scope="scope">
	              <div>
	                {{ scope.row.amount ? scope.row.amount : 0 | rounding }}</div>
	            </template>
	          </el-table-column>
	          

你可能感兴趣的:(vue.js,javascript,前端)