Former-commit-id: e83aaa31d66467d0106b9d2380f60a3ef3508a8d Former-commit-id: 7706b2b0054ebb4a81fa63c6ed0895605f92e363 Former-commit-id: 8a8fcf5678daded6ff7c79f537df141b947c8ee2
67 lines
1015 B
Markdown
67 lines
1015 B
Markdown
# Vue.$export
|
|
|
|
> 数据导出功能
|
|
|
|
## 注册插件
|
|
|
|
```
|
|
import pluginExport from '@/plugin/export'
|
|
Vue.use(pluginExport)
|
|
```
|
|
|
|
之后就可以在组件中使用 `this.$export` 来调用导出功能
|
|
|
|
## $export.csv()
|
|
|
|
此方法将数据以 `CSV` 格式导出
|
|
|
|
使用
|
|
|
|
```
|
|
this.$export.csv({
|
|
columns,
|
|
data
|
|
})
|
|
.then(data => {
|
|
// ...可选回调
|
|
})
|
|
```
|
|
|
|
参数
|
|
|
|
| 参数名 | 介绍 | 必选 | 值类型 | 可选值 | 默认值 |
|
|
| --- | --- | --- | --- | --- | --- |
|
|
| columns | 列 | 非 | Array | | 空数组 |
|
|
| data | 行数据 | 非 | Array | | 空数组 |
|
|
| noHeader | 不导出表头 | 非 | Boolean | | false |
|
|
| separator | 数据分隔符 | 非 | String | | , |
|
|
| quoted | 每项数据是否加引号 | 非 | Boolean | | false |
|
|
|
|
示例
|
|
|
|
```
|
|
const columns = [
|
|
{
|
|
label: '姓名',
|
|
prop: 'name'
|
|
},
|
|
{
|
|
label: '年龄',
|
|
prop: 'age'
|
|
}
|
|
]
|
|
const data = [
|
|
{
|
|
name: 'lucy',
|
|
age: 24
|
|
},
|
|
{
|
|
name: 'bob',
|
|
age: 26
|
|
}
|
|
]
|
|
this.$export.csv({
|
|
columns,
|
|
data
|
|
})
|
|
``` |