常用utils

 

 

 

用md5处理文件名。引入md5

 

 

 

将文件处理成base64

驼峰命名处理

function cached(fn) {
  const cache = Object.create(null);
  return function cachedFn(str) {
    const hit = cache[str];
    return hit || (cache[str] = fn(str));
  };
}

const regex = /-(\w)/g;
const camelize = cached(str =>
  str.replace(regex, (_, c) => (c ? c.toUpperCase() : ""))
);

例子:

 const attributes = Object.keys(this.$attrs).reduce((res, key) => {
      res[camelize(key)] = this.$attrs[key];
      return res;
    }, {})

 

posted @ 2020-06-04 22:05  TTtttt5  阅读(118)  评论(0编辑  收藏  举报