UNPKG

web-utils-super

Version:

前端函数库

35 lines (33 loc) 646 B
/** * @desc: 通过base64下载图片 * @param {String} dataUrl * @param {String} fileName */ function downByBase64(dataUrl, fileName) { const saveLink = document.createElementNS( "http://www.w3.org/1999/xhtml", "a" ); // 有效的内部空间URI saveLink.href = dataUrl; saveLink.download = fileName; const event = document.createEvent("MouseEvents"); event.initMouseEvent( "click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null ); saveLink.dispatchEvent(event); } module.exports = downByBase64;