1. let title = "我是标题";
    2. let table = this.$refs.reportXlsx.$el.innerHTML; //我是html内容
    3. let uri = 'data:application/vnd.ms-excel;base64,',
    4. 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>',
    5. base64 = function (s) {
    6. return window.btoa(unescape(encodeURIComponent(s)));
    7. },
    8. format = (s, c) => {
    9. return s.replace(/{(\w+)}/g,(m, p) => { return c[p]; })
    10. };
    11. let ctx = {
    12. worksheet: `${title}[${new Date()._format()}]`, //这是一个随机名字
    13. table
    14. };
    15. if (navigator.userAgent.indexOf("Firefox") > -1) {
    16. window.location.href = uri + base64(format(template, ctx))
    17. } else {
    18. //创建下载
    19. let link = document.createElement('a');
    20. link.setAttribute('href', uri + base64(format(template, ctx)));
    21. link.setAttribute('download', `${title}[${new Date()._format()}]`);
    22. // window.location.href = uri + base64(format(template, ctx))
    23. link.click();
    24. }