• #修改configure为false的对象属性 #修改File对象的name属性[code snippet]


    handelfileChange(e) {
      this.file = null; //init
      const FD = new FormData();
      let newNameFile = this.rewriteFileName(e.target.files[0]);
      FD.append("mFile", newNameFile);
      this.file = FD;
    },
    rewriteFileName(fileObj) {
      /* 后台在处理某文件没处理完时,前台再次传一个同名文件, 后台就会报错。 所以解决的方案就是每次都需要修改文件名,这个处理可以后台处理。 这里是在前台处理 */
      /* file 对象中的name 属性,原生是只读属性, 以下过程是通过新建一个变量,然后用name的getter访问这个变量, 就可以达到"改名"的目的 */
      Object.defineProperties(fileObj, {
          xname: {
              value:
                  // prettier-ignore
                  new Date().getTime() +"." +fileObj.name.split(".").at(-1) //at(-1) 用于取得最后一个元素
          },
          name: {
              get: function() {
                  // 复写name 的原始get方法
                  return this.xname;
              }
          }
      });
      return fileObj;
    },
    
  • 相关阅读:
    MySQL严格模式总结
    python筛选关键字---error
    将pem证书转换成p12格式证书
    ## 游戏网关源码赏析
    pid获取
    顺序io_磁盘队列
    nsq源码阅读3_编译nsqd
    nsq源码阅读2_核心数据结构
    nsq源码阅读1_目录结构
    如何设计Mqtt的Retain?
  • 原文地址:https://www.cnblogs.com/jaycethanks/p/15749291.html
Copyright © 2020-2023  润新知