1. 程式人生 > 其它 >【2022-12-02】連嶽摘抄

【2022-12-02】連嶽摘抄

公共方法 

utils 裡

export function downloadFile(obj, name, suffix) {   if (window.navigator.msSaveOrOpenBlob) {     // 相容IE     const blob = new Blob([obj])     const fileName = parseTime(new Date()) + '-' + name + '.' + suffix     navigator.msSaveBlob(blob, fileName)   } else {     const url = window.URL.createObjectURL(new Blob([obj]))     const link = document.createElement('a')     link.style.display = 'none'     link.href = url     const fileName = parseTime(new Date()) + '-' + name + '.' + suffix     link.setAttribute('download', fileName)     document.body.appendChild(link)     link.click()     document.body.removeChild(link)   } }   使用  import { downloadFile } from '@/utils/index'   rechargeLogDownload(params)         .then((result) => {           downloadFile(result, '充值記錄', 'xlsx')   //  downloadFile(result, '充值記錄', 'pdf')           this.downloadLoading = false         })         .catch(() => {           this.downloadLoading = false         })