需求:查询表格数据后,以Excel的形式,导出表格内的所有数据
<el-button class="btn-export" @click="exportData" type="primary">导出数据</el-button>
import axios from 'axios'
import { BASEURL } from '@/http/index'
async exportData() {
const exportParam = {
name: 'zhangsan',
age: '15',
}
axios.get(`${BASEURL}/students/export`, {
responseType: 'blob',
params: exportParam
}).then((res) => {
if (res.request.status === 200) {
const link = document.createElement('a')
const blob = new Blob([res.data], {
type: 'application/vnd.ms-excel'
})
link.href = URL.createObjectURL(blob)
const fileName = decodeURI(res[['headers']][['content-disposition']]
.split(';')[1].split('=')[1]) || '学生成绩.xlsx'
link.download = fileName
link.click()
}
})
}
|