// 下載圖片 downPhoto (path) { this.downloadFiles(path) }, // 下載 downloadFiles (content) { console.log(content) const downloadElement = document.createElement('a') // 創建下載的鏈接 let blob = this.base64ToBlob(content) // new Blob([content]); const href = window.URL.createObjectURL(blob) downloadElement.href = href downloadElement.download = '參保人相片.jpg' // 下載后的文件名 document.body.appendChild(downloadElement) downloadElement.click() // 下載 document.body.removeChild(downloadElement) // 下載完成 移除 a window.URL.revokeObjectURL(href) // 釋放blob對象 }, // base64轉blob base64ToBlob(code) { let parts = code.split(';base64,') let contentType = parts[0].split(':')[1] let raw = window.atob(parts[1]) let rawLength = raw.length let uInt8Array = new Uint8Array(rawLength) for (let i = 0; i < rawLength; ++i) { uInt8Array[i] = raw.charCodeAt(i) } return new Blob([uInt8Array], {type: contentType}) },
<button class="cancel-btn cursor" @click="downPhoto(dataDetail.photo64Byte)">下載圖片</button>
