I have studied these two days and I feel that I have a lot of knowledge points, so I will add some small notes today.
In the project, v-for the data returned by the background into a table, and then you need to export this table as EXCEL
Just talk about how to do it.
1. Three dependencies need to be installed:
npm install -S file-saver xlsx npm install -D script-loader
2. Create a new folder in the project: (vendor----------------------------------------------------------------------------------------------------------------
Place two files and .
and file download address:Export2Exce_jb51.rar
3. In .vue file
Write these two methods: where list is the content of the table
export2Excel() { ([], () => { const { export_json_to_excel } = require('../../vendor/Export2Excel'); const tHeader = ['Serial number', 'IMSI', 'MSISDN', 'Dict number', 'Name']; const filterVal = ['ID', 'imsi', 'msisdn', 'address', 'name']; const list = ; const data = (filterVal, list); export_json_to_excel(tHeader, data, 'List excel'); }) }, formatJson(filterVal, jsonData) { return (v => (j => v[j])) }
4. Button export calls export2Excel method
Note: If webpack reports parsing error:
Add 'vendor': (__dirname, '../src/vendor') to resolve alias,
It can be solved
Also: alias is a configuration alias
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.