Bootstrap

开发中常用的需求代码

1. 下载模板

自定义excel放到public文件夹下

    // 下载模版
    const downTemplate = () => {
      const link = document.createElement("a");
      link.style.display = "none";
      link.href =
        window.location.protocol +
        "//" +
        window.location.host +
        "/xxxxx/自定义excel.xlsx";
      link.setAttribute("download", "");
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    };

2. 深度克隆

    cloneDeep(obj) {
        if (typeof obj !== 'object' || obj == null) {
            return obj
        }
        let result
        if (obj instanceof Array) {
            result = []
        } else {
            result = {}
        }
        for (let key in obj) {
            if (Object.prototype.hasOwnProperty.call(obj, key)) {
                result[key] = this.cloneDeep(obj[key])
            }
        }
        return result
    }

 

;