zoukankan      html  css  js  c++  java
  • vue elemnt upload 提交带参数

    html

      <el-upload class="avatar-uploader" action="http://yjyhnav1.rdmate.com/ad_admin/" :http-request="upLoad" :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                      <img v-if="headUrl" :src="headUrl" class="avatar">
                      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
    js
     upLoad(file) {
          const formData = new FormData();
          formData.append('logo', file.file);
          formData.append('activity_id', this.activity_id);
          console.log(file, "上传的图片");
    //发送请求
          LOGO(
            formData
          ).then(res => {
            //  that.imgId = res.data.data
            Bus.$emit('logourl', res.data.logo.url)
            this.headUrl = res.data.logo.url

          }).catch((error) => {
            // this.$message.error('头像上传失败,请重新上传!');

          })

        },
     beforeAvatarUpload(file) {
          const isJPG = file.type === 'image/jpeg';
          const isLt3M = file.size / 1024 / 1024 < 3;

          if (!isJPG) {
            this.$message.error('上传头像图片只能是 JPG 格式!');
          }
          if (!isLt3M) {
            this.$message.error('上传头像图片大小不能超过 3MB!');
          }
          return isJPG && isLt3M;
        },
     handleAvatarSuccess(res, file) {
          this.headUrl = URL.createObjectURL(file.raw);

        },
    正道的光终将来临,当太阳升起的时候,光芒总会普照大地温暖人间。些许的阴霾也终会有被阳光洒满的一天
  • 相关阅读:
    思考未来:你的目标是什么
    从非同凡响开始:绝不要做他人也在做的事
    Elasticsearch的内置分词器
    Elasticsearch倒排索引的核心组成
    Session 与 JWT
    vue全屏组件
    css弹性盒骰子
    es6模块化
    移动端适配
    echarts-3D地图
  • 原文地址:https://www.cnblogs.com/sjruxe/p/14486351.html
Copyright © 2011-2022 走看看