实现前端xlsx和csv文件的解析,解析完成以后将文件数据传给后端

 // 导入excel,csv格式
    importExcel(file) {

      if (file.status !== 'ready') return
 // 通过截取字符串获取文件格式
      const types = file.name.split('.')[1]
      判断当前文件格式是否是xlsx
      if (types !== 'xlsx') {
        this.$notify({
          title: '提示',
          message: `文件格式不正确,只支持.xlsx文件`,
          type: 'error',
        })
        return
      }
      this.fileExcel(file).then((tabJson) => {
        console.log('解析文件', tabJson)
        if (tabJson && tabJson.length > 0) {
          this.xlsxJson = tabJson
          console.log('解析文件1', this.xlsxJson)
        }
        if (this.totalLength > 5000) {
          this.openError()
          return
        }
        if (this.tableData.length) {
          // 有错误!!!!
          this.dialogVisible = true
        } else {
          this.importLoading = true
          this.submitUpload()
        }
      })
    },



        
点击上传
支持扩展名:'xlsx'
点击下载商品清单模版

你可能感兴趣的:(前端)