模板模块:
<el-table-column label="文件大小" prop="FileSize">
<template slot-scope="scope">
<span>{{ scope.row.FileSize | filterType}}</span>
</template>
</el-table-column>
js模块:
filters:{
filterType:function(val){
if(val === 0) return "0 B"
var k = 1024;
var sizes = ['B','KB','MB','GB','PB','TB','EB','ZB','YB'],
i = Math.floor(Math.log(val) / Math.log(k));
return (val / Math.pow(k,i)).toPrecision(3) + "" + sizes[i]
}
}