干 H5 积累的经验

String复杂情况,多个同字符替换

replaceAll(str, searchValue, replaceValue) {
      return str.replace(new RegExp(searchValue,"gm"),replaceValue);
    },
  • str:需要替换的字符串
  • searchValue:需要替换的字符
  • replaceValue:要替换的字符

点击下载获取下载链接创建<a>标签下载

async btnExport(url) {
      let that = this;
      this.loading = true;
      let a = document.createElement('a');//创建a标签
      a.href =  url;//文件url
      document.body.appendChild(a);
      a.click();//触发下载
      document.body.removeChild(a);
      setTimeout(async () => {
        that.loading = false;
      }, 4000);//4s后关闭loading,可以根据情况增减
    },
  • url:异步请求获取的链接地址

后续持续更新...

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容