**
文件大小单位换算B,MB,GB…
**1.elementui 中的table进行内容格式化
<el-table-column key="origName" prop="origName" label="文件名称" align="center"></el-table-column>
<el-table-column key="fileSize" prop="fileSize" label="文件大小" align="center">
<template slot-scope="scope">
<span>{{ scope.row.fileSize | filterType }}</span>
</template>
</el-table-column>
2.在vue中使用filters过滤器
watch: {
},
//过滤文件大小
filters: {
filterType: function (val) {
if (val === 0) return "0 B";
var k = 1024;
var sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
i = Math.floor(Math.log(val) / Math.log(k));
return (val / Math.pow(k, i)).toPrecision(3) + " " + sizes[i];
},
},
|