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

How to operate vue to export the table in v-for

php中世界最好的语言
Release: 2018-05-31 10:29:07
Original
1460 people have browsed it

This time I will show you how to operate vue to export the table in v-for , what are the precautions when operating vue to export the table in v-for, the following is the actual combat Let’s take a look at the case.

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:

How to use Vue to implement tree view data

What are the methods for JS to implement DOM tree traversal?

The above is the detailed content of How to operate vue to export the table 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!