vue.runtime.esm.js?2b0e:619 [Vue warn]:Computed property “imgUrl“ was assigned to but it has no sett
原创
©著作权归作者所有:来自51CTO博客作者wx6316c4e40e2ec的原创作品,请联系作者获取转载授权,否则将追究法律责任
报错信息:使用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里加这个属性给imageUrl赋值
data() {
return {
imageUrl:''
}
},
把成功回调里的:this.imgUrl 改成this.imageUrl别的不用改
handleAvatarSuccess(res, file) {
this.imageUrl= res.data;
this.emitInput(res.data);
},