elui实现多张图片上传

2022-03-08 07:15:21 浏览数 (1)

效果图
2022-03-08_071321.png2022-03-08_071321.png
实现步骤
代码语言:javascript复制
<el-form-item label="产品图" prop="imgurls">
          <el-upload
            class="avatar-uploader"
            action=""
            :limit="3"
            :http-request="getFile"
            :show-file-list="false">
            <div v-for="(item, index) in form.imgurls">
              <img v-if="item" :src="item" class="avatar">
            </div>
            <i v-if="form.imgurls.length < 3" class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>

limit属性可以限制上传图片的数量

代码语言:javascript复制
getFile2(item) {
        this.file = item.file
        let formData = new FormData();
        formData.append("file", this.file);
        uploadFile(formData).then(response => {
          this.msgSuccess("商品icon图上传成功!");
          this.form.icon = response.data.imgShowUrl;
          console.log(this.form.icon)
        });
      },

0 人点赞