vue中excel导出(不兼容IE)

页面中先加上这些
<template>
    <div>
        <div id='content'>
            开始日期<input type='text' v-model='excelBegin'>
            结速日期<input type='text' v-model='excelEnd'>
            <table>内容table>
        div>
        <button>导出button>
    div>
template>
<script>
    var idTmr;
    function method1(tableid) {//整个表格拷贝到EXCEL中
        tableToExcel(tableid)
    }
    function Cleanup() {
        window.clearInterval(idTmr);
        CollectGarbage();
    }
    var tableToExcel;

var vm = new Vue({
    el:'#app',
    data:{
        excelBegin:'2018-01-01',
        excelEnd:'2018-01-30'
    },
    methods:{
        excelDownload(){
            methodl(id)
        }
    },
    mounted:function(){
        tableToExcel = (function () {
            var uri = 'data:application/vnd.ms-excel;base64,',
                template = '' +
                    ''+
                    '' +
                    '' +
                    '

统计

'
+ '

' + '

' + '' + '' + '' + '' + '' + '' + '{table}
开始时间:{begin}结束时间:{end}
'
+ '', base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) } return function (table, name) { console.log(vm.formData4.begin) if (!table.nodeType) table = document.getElementById(table) console.log(table.innerHTML) var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML, begin: vm.excelBegin, end: vm.excelEnd } window.location.href = uri + base64(format(template, ctx)) } })() } })
script>

你可能感兴趣的:(vue-js,excel)