Files
mes-ui-d2/static/markdownFiles/article/插件 - 导入 - csv.md
李杨 b1e4bd2b28 no message
Former-commit-id: 87f96c930a1d89b148c01ac2401e13ff6a71d12e
Former-commit-id: 9d5e41f4b05c4b2c984d2f61f97e73279c200f5e
Former-commit-id: bbc175f9fc5af0f3b4557cb5082074757b2afa0f
2018-02-15 14:24:28 +08:00

558 B

解析 CSV 文件使用 PapaParse

// 导入插件
import papa from 'papaparse'

//在选择文件后处理数据
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
}

详细的papaparse使用API请移步官网文档