no message
Former-commit-id: 28ec2beb0befdc6a796458fbcc1a0c3786fb8d62 Former-commit-id: 82768e538a271a2354616cd01f84fd73631a62b2 Former-commit-id: 450e74928f5d6bdba20e01ce57bebdfde0d512a1
This commit is contained in:
62
static/md/插件 - 导入.md
Normal file
62
static/md/插件 - 导入.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# Vue.$import
|
||||
|
||||
本框架集成了数据导入功能,并包装成插件
|
||||
|
||||
## 注册插件
|
||||
|
||||
> 默认已经注册,可以直接使用
|
||||
|
||||
```
|
||||
import pluginImport from '@/plugin/import'
|
||||
Vue.use(pluginImport)
|
||||
```
|
||||
|
||||
之后就可以在组件中使用 `this.$import` 来调用导出功能
|
||||
|
||||
## Vue.$import.csv()
|
||||
|
||||
导入csv文件,并且返回一个 `Promise` 对象
|
||||
|
||||
```
|
||||
// 在选择文件后调用
|
||||
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` 对象
|
||||
|
||||
**注意 导入的表格文件第一行应为表头**
|
||||
|
||||
参考下述示例使用
|
||||
|
||||
```
|
||||
// 在选择文件后调用
|
||||
handleUpload (file) {
|
||||
this.$import.xlsx(file)
|
||||
.then(({header, results}) => {
|
||||
// header 为表头
|
||||
// results 为内容
|
||||
this.table.columns = header.map(e => {
|
||||
return {
|
||||
label: e,
|
||||
prop: e
|
||||
}
|
||||
})
|
||||
this.table.data = results
|
||||
})
|
||||
// 阻止默认的上传
|
||||
return false
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user