Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the steps to export tables in v-for

php中世界最好的语言
Release: 2018-05-12 11:22:18
Original
2154 people have browsed it

This time I will bring you a detailed explanation of the steps to export the table in v-for. What are the notes for exporting the table in v-for? The following is a practical case. Let’s take a look. take a look.

1. NeedinstallationThe following dependencies

 npm install -S file-saver xlsx
 npm install -D script-loader
Copy after login

2. Create a new file in the project Folder: (vendor---name as you like)

Place two files Blob.js and Export2Excel.js in it.

3. In the .vue file

Write these two methods: list is the content of the table

//export2Excel是你点击导出所绑定的方法名
    export2Excel() {
      require.ensure([], () => {
        const { export_json_to_excel } = require('../../vendor/Export2Excel');//其中自己的路径也要注意下
        const tHeader = ['序号', 'IMSI', 'MSISDN', '证件号码', '姓名'];//表格的头的名称
        const filterVal = ['ID', 'imsi', 'msisdn', 'address', 'name'];//对应的内容的名字,一定要一 一 对应
        const list = this.tableData;//tableData是你表单所绑定的数据名称,一定要对应
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, '列表excel');//列表excel这个是导出以后表格的名称,根据需要自行更改
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    }
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed explanation of JS cross-domain POST implementation steps

Usage of region selector (V-Distpicker) component Detailed explanation

The above is the detailed content of Detailed explanation of the steps to export tables in v-for. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!