no message
Former-commit-id: 0a96bb54e9270e451e59b72e00e35053a7c0e152 Former-commit-id: c250ba90da6546626b9831847630aae786c88344 Former-commit-id: c1182b1bdc6ea9b3934275286a93e2760a643bfe
This commit is contained in:
56
src/pages/demo/plugins/papaParse/demo.vue
Normal file
56
src/pages/demo/plugins/papaParse/demo.vue
Normal file
@@ -0,0 +1,56 @@
|
||||
<template>
|
||||
<Container>
|
||||
<!-- <template slot="title">演示</tempalte> -->
|
||||
<p slot="more"><GithubLink url="https://github.com/mholt/PapaParse"></GithubLink></p>
|
||||
<el-upload
|
||||
:before-upload="handleUpload"
|
||||
action="default">
|
||||
<el-button>选择一个CSV文件</el-button>
|
||||
</el-upload>
|
||||
<br>
|
||||
<el-table
|
||||
v-bind="table"
|
||||
style="width: 100%">
|
||||
<el-table-column
|
||||
v-for="(item, index) in table.columns"
|
||||
:key="index"
|
||||
:prop="item.prop"
|
||||
:label="item.label">
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import papa from 'papaparse'
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
table: {
|
||||
columns: [],
|
||||
data: [],
|
||||
size: 'mini',
|
||||
stripe: true,
|
||||
border: true
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleUpload (file) {
|
||||
papa.parse(file, {
|
||||
header: true,
|
||||
skipEmptyLines: true,
|
||||
complete: (results, file) => {
|
||||
this.table.columns = Object.keys(results.data[0]).map(e => ({
|
||||
label: e,
|
||||
prop: e
|
||||
}))
|
||||
this.table.data = results.data
|
||||
}
|
||||
})
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user