el-upload 简单使用

      <el-upload
        ref="upload"
        :limit="1"
        :http-request="handleImport"
        action=""
        :auto-upload="true"
        :show-file-list="false"
        class="upload-button"
        accept=".xls,.xlsx">
        <el-col :span="1.5">
          <el-button
            type="warning"
            icon="el-icon-upload2"
            size="mini"
          >导入</el-button>
        </el-col>
      </el-upload>
    handleImport(file) {
      const _file = file.file
      const isLt10M = _file.size / 1024 / 1024 < 10
      // 通过 FormData 对象上传文件
      var formData = new FormData()
      formData.append('file', _file)
      if (!isLt10M) {
        this.$message.error('请上传10M以下的.xlsx文件')
        return
      }
      this.$refs['upload'].clearFiles()
      // 发起请求
      workloadUpload(formData).then(res => {
        this.$refs.upload.clearFiles()
        if (res.code === 200) {
          // 成功
          this.getList()
        } else {
          this.$message({
            type: 'warning',
            message: res.msg
          })
        }
      }).catch(e => {})
    },

`<el-upload-list>` 是 Element UI 中的一个上传组件,用于展示已上传的文件列表。下面是一个简单使用示例: ```html <template> <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/" :on-success="handleSuccess" :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileList" list-type="picture" :auto-upload="false" multiple> <el-button slot="trigger">选取文件</el-button> <el-button style="margin-left: 10px;" type="primary" @click="submitUpload">上传到服务器</el-button> <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> </el-upload> <el-upload-list :deletable="true" :list-type="'picture-card'" :disabled="true" :items="fileList"></el-upload-list> </template> <script> export default { data() { return { fileList: [] } }, methods: { handleSuccess(response, file, fileList) { console.log(response, file, fileList); }, handlePreview(file) { console.log(file); }, handleRemove(file, fileList) { console.log(file, fileList); }, submitUpload() { this.$refs.upload.submit(); } } } </script> ``` 在上面的示例中,我们通过 `:file-list` 属性将已上传的文件列表传递给 `<el-upload>` 组件,并在上传成功、预览、删除等事件中更新文件列表。然后,我们在页面中使用 `<el-upload-list>` 组件展示已上传的文件列表,通过 `:items` 属性将文件列表传递给组件即可。 需要注意的是,`<el-upload-list>` 组件只是一个展示已上传文件列表的组件,需要与 `<el-upload>` 组件一起使用。此外,我们也可以使用一些其他的属性,如 `:deletable` 控制是否显示删除按钮,`:disabled` 控制整个列表的可编辑性,`:list-type` 控制列表的样式等等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江湖行骗老中医

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值