全局应用千分位过滤器
新建util.js
export const formatToThousands = (num) => {
num = num + ''
if (!num.includes('.')) {
num += '.'
}
return num.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
return $1 + ','
}).replace(/\.$/, '')
}
在main.js中引用
import { formatToThousands } from './utils/util'
Vue.prototype.formatToThousands = formatToThousands
在项目中使用
<el-table-column prop="num" label="数量" :show-overflow-tooltip="true">
<template slot-scope="scope">
<span>{{formatToThousands(scope.row.num)}}</span>
</template>
</el-table-column>