1.下载 file-saver 、xlsx 、script-loader
2.网上下载js文件
3. methods代码:
handleExport() {
var obj = {
provinceId: null,
cityId: this.districtId===null?this.cityId:null,
districtId: this.districtId,
names: this.searchForm.reservoirsname,
}
const list = await getIrrigationList(obj);
list.rows.map(item => {
item.xzqh = item.qName?item.sName + item.cName + item.qName:item.sName + item.cName
})
const excel = await import('@/vendor/Export2Excel')
let tHeader = [] //导出文件的头部名称
let filterVal = [] //导出文件的table属性
let filename = '信息' //导出文件的文件名称
tHeader = ['名称', '地址','描述','备注']
filterVal = ['name', 'address', 'decription', 'remark']
const data = this.formatJson(filterVal, list.rows)
excel.export_json_to_excel({
header: tHeader,
data,
filename: filename// table-list
})
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => v[j]))
},
4.html代码