js导出文件

fakeClick (obj) {
    var ev = document.createEvent('MouseEvents')
    ev.initMouseEvent(
    'click', true, false, window, 0, 0, 0, 0, 0
    , false, false, false, false, 0, null
    )
   obj.dispatchEvent(ev)
},
exportRaw (name, data) {
   var urlObject = window.URL || window.webkitURL || window
   var exportBlob = new Blob([data])
   var saveLink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
   saveLink.href = urlObject.createObjectURL(exportBlob)
   saveLink.download = name
   this.fakeClick(saveLink)
}

调用exportRaw方法,参数一为 文件名,参数二为文件内容

posted @ 2018-07-04 18:09  衰草寒烟  阅读(287)  评论(0编辑  收藏  举报