vue2 过滤器filter的使用,filter位置和methods统计
效果
template部分
<el-table-column label="文件大小" prop="FileSize"> <template slot-scope="scope"> <span>{{ scope.row.FileSize | filterType}}</span> </template> </el-table-column>
script / 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] } }
下班~