Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • 文件大小过滤器

文件大小过滤器

import Vue from "vue";

Vue.filter("transformByte", function (bytes) {
  if (bytes === 0 || bytes === "0") return "0 B";
  if (!bytes) return "";
  let k = 1024;
  let sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
  let i = Math.floor(Math.log(bytes) / Math.log(k));
  return (bytes / Math.pow(k, i)).toFixed(2) + " " + sizes[i];
});

Vue.filter("limitChar", function (str, num, suffix) {
  if (str && str.length >= num) {
    str = str.substring(0, num) + suffix || "";
  }
  return str || "";
});
Edit this page
最近更新: 2025/6/27 02:24
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人