{{ size| | formatbytes}}
1.组件里使用
在 filters 属性里面:
filters: {formatbytes: function (bytes) {if (bytes === 0) return '0 B';var k = 1000, // or 1024sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],i = Math.floor(Math.log(bytes) / Math.log(k));return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];}}
2.全局使用的
main.js// 素材大小格式化Vue.filter("formatbytes", function (bytes) {if (bytes === 0) return "0 B";var k = 1000, // or 1024sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],i = Math.floor(Math.log(bytes) / Math.log(k));return (bytes / Math.pow(k, i)).toPrecision(3) + " " + sizes[i];});