From 38de16e9120d83495c03e58dc791ba5ac8928b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=9D=A8?= <1711467488@qq.com> Date: Sun, 11 Feb 2018 18:10:34 +0800 Subject: [PATCH] no message Former-commit-id: 4d819afc5d57441ab734ed1ad08d5a647b630a76 Former-commit-id: 5268af71a59b7da8106255c21097796295a65a33 Former-commit-id: b6177a970d7cd869a4d0e409d81bfd1785606503 --- src/plugin/export/index.js | 31 ++++++----- .../markdownFiles/article/插件 - 导出数据.md | 53 ++++++++++++++++++- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/plugin/export/index.js b/src/plugin/export/index.js index 47f00bb3..769cd2b8 100644 --- a/src/plugin/export/index.js +++ b/src/plugin/export/index.js @@ -26,18 +26,25 @@ export default { }, // 导出 Excel excel (params) { - // 默认值 - const paramsDefault = { - columns: [], - data: [] - } - // 合并参数 - const _params = Object.assign({}, paramsDefault, params) - // 从参数中派生数据 - const header = _params.columns.map(e => e.label) - const data = _params.data.map(row => _params.columns.map(col => row[col.prop])) - // 导出 Excel - Excel.export_json_to_excel(header, data, 'demo') + return new Promise((resolve, reject) => { + // 默认值 + const paramsDefault = { + columns: [], + data: [] + } + // 合并参数 + const _params = Object.assign({}, paramsDefault, params) + // 从参数中派生数据 + const header = _params.columns.map(e => e.label) + const data = _params.data.map(row => _params.columns.map(col => row[col.prop])) + // 导出 Excel + Excel.export_json_to_excel(header, data, 'demo') + // 完成 + resolve({ + header, + data + }) + }) } } } diff --git a/static/markdownFiles/article/插件 - 导出数据.md b/static/markdownFiles/article/插件 - 导出数据.md index 7cce1b34..e0468425 100644 --- a/static/markdownFiles/article/插件 - 导出数据.md +++ b/static/markdownFiles/article/插件 - 导出数据.md @@ -66,4 +66,55 @@ this.$export.csv({ columns, data }) -``` \ No newline at end of file +``` + +## Vue.$export.excel() + +使用 + +``` +this.$export.excel({ + columns, + data +}) + .then(data => { + // ...可选回调 + }) +``` + +参数 + +| 参数名 | 介绍 | 必选 | 值类型 | 可选值 | 默认值 | +| --- | --- | --- | --- | --- | --- | +| columns | 列 | 非 | Array | | 空数组 | +| data | 行数据 | 非 | Array | | 空数组 | + +示例 + +``` +const columns = [ + { + label: '姓名', + prop: 'name' + }, + { + label: '年龄', + prop: 'age' + } +] +const data = [ + { + name: 'lucy', + age: 24 + }, + { + name: 'bob', + age: 26 + } +] +this.$export.excel({ + columns, + data +}) +``` +