vue导出excel表格
时间: 2023-05-12 18:07:42 浏览: 138
可以使用第三方库如"xlsx"或"file-saver"来实现Vue导出Excel表格。以下是一个示例代码:
<template>
<div>
<button @click="exportExcel">导出Excel</button>
</div>
</template>
<script>
import XLSX from 'xlsx'
import FileSaver from 'file-saver'
export default {
methods: {
exportExcel() {
const data = [
['姓名', '年龄', '性别'],
['张三', 18, '男'],
['李四', 20, '女'],
['王五', 22, '男']
]
const ws = XLSX.utils.aoa_to_sheet(data)
const wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' })
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), 'example.xlsx')
}
}
}
</script>
阅读全文