base64转word文档并且下载

shows(item){
              console.log(item)
            if (item.FILETYPE.substring(item.FILETYPE.lastIndexOf('.')+1,item.FILETYPE.length)=='docx') {
            const dataURLtoBlob = function (dataurl) {
                let arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
                    bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
                while (n--) {
                    u8arr[n] = bstr.charCodeAt(n);
                }
                return new Blob([u8arr], { type: mime });
            }
             
            const  downloadFile = function downloadFile(url,name=item.CNAME){
                let a = document.createElement("a")
                a.setAttribute("href",url)
                a.setAttribute("download",name)
                a.setAttribute("target","_blank")
                let clickEvent = document.createEvent("MouseEvents");
                clickEvent.initEvent("click", true, true);  
                a.dispatchEvent(clickEvent);
            }
             
            const downloadFileByBase64 = function (base64,name){
                let myBlob = dataURLtoBlob(base64)
                let myUrl = URL.createObjectURL(myBlob)
                downloadFile(myUrl,name)
            }
            downloadFileByBase64('data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,'+ item.ANNEXCONTENT)
            }else{
                    this.imgsrc='data:image/jpeg;base64,'+ item.ANNEXCONTENT
                    this.modal3_show=true
                }
            },
上一篇:338. 比特位计数


下一篇:wx.getImageInfo和wx.downloadFile下载用户头像报错(小程序canvas以及小程序图片下载部分)