2017-06-14 57 views

回答

7

安装numeral.js

npm install numeral --save 

定义自定义过滤器:

<script> 
    var numeral = require("numeral"); 

    Vue.filter("formatNumber", function (value) { 
    return numeral(value).format("0,0"); // displaying other groupings/separators is possible, look at the docs 
    }); 

    export default 
    { 
    ... 
    } 
</script> 

使用它:

<tr v-for="(item, key, index) in tableRows"> 
    <td>{{item.integerValue | formatNumber}}</td> 
</tr> 
+2

虽然可能更好地移动过滤器功能之外的需求。 – Cobaltway