let title = "我是标题";let table = this.$refs.reportXlsx.$el.innerHTML; //我是html内容let uri = 'data:application/vnd.ms-excel;base64,', template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta charset="UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body>{table}</body></html>', base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))); }, format = (s, c) => { return s.replace(/{(\w+)}/g,(m, p) => { return c[p]; }) };let ctx = { worksheet: `${title}[${new Date()._format()}]`, //这是一个随机名字 table};if (navigator.userAgent.indexOf("Firefox") > -1) { window.location.href = uri + base64(format(template, ctx))} else { //创建下载 let link = document.createElement('a'); link.setAttribute('href', uri + base64(format(template, ctx))); link.setAttribute('download', `${title}[${new Date()._format()}]`); // window.location.href = uri + base64(format(template, ctx)) link.click();}