Vue button to export Excel files. NPM install -s file-saver XLSX NPM install -d script-loader
2. Create a new folder in the project (vendor-name whatever) and place two files blob. js and Export2Excel. Baidu cloud: pan.baidu.com/s/1vJ7RnNMK… Extraction code: Y91K
3. Call the method
exportExcel() {             require.ensure([], () => { const { export_json_to_excel } = require('.. /.. /vendor/Export2Excel')
const tHeader = ['Order Number'.'User account'.'Order Type'.'Order Status'.'Trade Name'.'Quantity of goods'.'Unit price of goods'.'Total order amount'.'Creation time'.'Time of payment']
const filterVal = ['orderNo'.'userAccount'.'orderType'.'orderStatus'.'productName'.'productNum'.'productUnitPrice'.'orderPrice'.'orderSubmitTime'.'orderPayTime']
const list = res.data
const data = this.formatJson(filterVal, list)
export_json_to_excel(tHeader, data, 'Order List')
})
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => v[j]))
},
Copy the code
Note: If webpack reports a resolution error:
Add ‘vendor’ : path.resolve(__dirname, ‘.. / SRC /vendor ‘), alias is the configuration alias