elementUI中图片上传upload组件,上传图片数据到后台

结构:

        <el-upload
          :action="api.base+api.uploadotherpic"
          list-type="picture-card"
          :file-list="fileList"
          with-credentials
          :before-upload="beforeUpload"
          :on-remove="afterRemove">
          <i class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>

上传:

 beforeUpload(file) {
      var code = store.state.shop_code;
      let fd = new FormData();//通过form数据格式来传
      fd.append("picFile", file); //传文件
      fd.append("shop_code", code); //传其他参数
      var url = api.uploadotherpic;
      this.$http
        .post(url, fd)
        .then(res => {
          console.log(res.data);
          let data = res.data;
          if (data.code == 200) {
            this.$message({
              message: "上传成功",
              type: "success"
            });

            //再次请求数据,实现本地与服务器内容一致,解决图片删除失败的bug
            var code = store.state.shop_code;
            this.getImgs(code);//封装好的请求后台图片的axios请求
          } else {
            this.$message.error(data.msg);
          }
        })
        .catch(error => {
          // console.log(error);
        });
    },

//结合上一片博文:axios封装

 

  • 3
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值