1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Vue.filter过滤器存储单位换算按KB M G显示字节大小

Vue.filter过滤器存储单位换算按KB M G显示字节大小

时间:2024-08-26 10:03:56

相关推荐

Vue.filter过滤器存储单位换算按KB  M  G显示字节大小

{{ 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];});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。