Files
mes-ui-d2/static/markdownFiles/article/插件 - 导入.md
李杨 34630dca3b no message
Former-commit-id: 5ad7ba5e0ab03190c9d778ccf41d9bef4c7eb7c8
Former-commit-id: f4b384d5efbec542b2953009e99338b3cb3bed63
Former-commit-id: f9914c43cef036556edd17c04ca7424078fbb2c7
2018-02-15 23:24:31 +08:00

72 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Vue.$import
本框架集成了数据导入功能,并包装成插件
## 注册插件
> 默认已经注册,可以直接使用
```
import pluginImport from '@/plugin/import'
Vue.use(pluginImport)
```
之后就可以在组件中使用 `this.$import` 来调用导出功能
## Vue.$import.csv()
导入csv文件并且返回一个 `Promise` 对象
参数
| 参数名 | 介绍 | 必选 | 值类型 | 可选值 | 默认值 |
| --- | --- | --- | --- | --- | --- |
| file | 选择的文件 | 是 | File | | |
使用
```
// 在选择文件后调用
handleUpload (file) {
this.$import.csv(file)
.then(res => {
this.table.columns = Object.keys(res.data[0]).map(e => ({
label: e,
prop: e
}))
this.table.data = res.data
})
// 阻止默认的上传
return false
}
```
## Vue.$import.xlsx()
导入xlsx文件并且返回一个 `Promise` 对象
参数
| 参数名 | 介绍 | 必选 | 值类型 | 可选值 | 默认值 |
| --- | --- | --- | --- | --- | --- |
| file | 选择的文件 | 是 | File | | |
使用
```
// 在选择文件后调用
handleUpload (file) {
this.$import.xlsx(file)
.then(({header, results}) => {
this.table.columns = header.map(e => {
return {
label: e,
prop: e
}
})
this.table.data = results
})
// 阻止默认的上传
return false
}
```