js 将数据保存到本地

  • name 文件名
  • data 数据
  • type mime类型
saveAs: function (name, data, type) { 
    const element = document.createElementNS("http://www.w3.org/1999/xhtml", "a"),
        ev = document.createEvent("MouseEvents"),
        urlObject = window.URL || window.webkitURL || window,
        export_blob = new Blob([data], { type: type ? type : ''});
    element.href = urlObject.createObjectURL(export_blob);
    element.download = name;
    ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    element.dispatchEvent(ev);
    urlObject.revokeObjectURL(element.href);
    element.href = '';
}
    原文作者:路过君_P
    原文地址: https://blog.csdn.net/zhoudingding/article/details/108224153
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞