Former-commit-id: dd4c302e448f871376ab1298240b44aa3d3e1643 [formerly dd4c302e448f871376ab1298240b44aa3d3e1643 [formerly dd4c302e448f871376ab1298240b44aa3d3e1643 [formerly dd4c302e448f871376ab1298240b44aa3d3e1643 [formerly 8bbdd72ba63cd9161b2b2e51826b8813e8c9fffc [formerly e7d3090ad5a6f6801b32d0abce9a4e9291fcc0e7]]]]] Former-commit-id: 1be4f8ac464528598b8a52649c107686d01c08d8 Former-commit-id: 7317640b0da3a039d8ca5b6457c1263fc1261272 Former-commit-id: 29d4f7df0be48866f4309a012d38e008e1725438 [formerly 9ee9681b4a3200cc3b344673e83d9f5e4343f07a] Former-commit-id: fddc0694f8fbf921142069e11ff694ea218fa0d9 Former-commit-id: 92059d07f780aa09aaff77faf9bc41a8bd6269f0 Former-commit-id: aef5ddaf56545324913a9b425e7f8b7c3ed45518 Former-commit-id: 279be73fde5a48ddc78a258a2ea55a3b0d64fe2b Former-commit-id: b970cb8f0bbe694a3bf733e726f8c833a1f3f511
1.2 KiB
1.2 KiB
表格导入
本框架集成了数据导入功能,并包装成插件
注册插件
import pluginImport from '@/plugin/import'
Vue.use(pluginImport)
之后就可以在组件中使用 this.$import 来调用导出功能
::: tip d2admin 已经帮你注册好,可以直接使用,无需写上面的代码 :::
导入 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
}
导入 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
}