其他分享
首页 > 其他分享> > vue.runtime.esm.js?2b0e:619 [Vue warn]:Computed property “imgUrl“ was assigned to but it has no sett

vue.runtime.esm.js?2b0e:619 [Vue warn]:Computed property “imgUrl“ was assigned to but it has no sett

作者:互联网

报错信息:使用elementui上传图片报错可以上传OSS也可以上传数据库页面就是不展示
在这里插入图片描述

解释:
vue.runtime.esm.js吗?2b0e:619 [Vue warn]:计算属性“imgur”被分配给但它没有setter。
中发现的
< SingleUpload >在src /组件/上传/ singleUpload.vue
< ElFormItem >在包/形式/ src / form-item.vue
< ElForm >在包/形式/ src / form.vue
< ElDialog > / src / component.vue在包/对话框
<品牌>在src /视图/项目经理/品牌/ Brand.vue
<回家>在src /组件/共同/ Home.vue
在src / App.vue <应用>
根> <

报错代码:

<template>
  <el-upload
          class="avatar-uploader"
          action="http://localhost:8080/upload"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload">
    <img v-if="imgUrl" :src="imgUrl" class="avatar">
    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  </el-upload>
</template>

<script>
  export default {
    name: "SingleUpload",
    props:{
      value:String
    },
    computed:{
      imgUrl(){
        return this.value;
      }
    },
    data() {
      return {}
    },
    methods: {
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;
        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      handleAvatarSuccess(res, file) {
        this.imgUrl = res.data;
        this.emitInput(res.data);
      },
      emitInput(val){
        this.$emit('input',val);
      }
    },
    mounted() {
    }
  }
</script>

<style >
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    width: 90px;
    height: 90px;
    display: block;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 90px;
    height: 90px;
    line-height: 90px;
    text-align: center;
  }
  .avatar {
    width: 90px;
    height: 90px;
    display: block;
  }
</style>

最后发现少了点东西:data里加这个属性页面上的imgUrl 都替换成imageUr,给imageUr赋值

	data() {
      return {
        imageUr:''
      }
    }

注意:computed里不用改不然还是报错
在这里插入图片描述

标签:src,619,2b0e,上传,assigned,vue,报错,data,90px
来源: https://blog.csdn.net/jq1223/article/details/114680917