近日在写项目的时候发现在dialog中上传图片不会回显,上传完还是显示空白。
后台返回的图片地址也正常,但就是不显示。想了想可能是在dialog中已经弹出显示的对话框不能根据数据刷新节点,于是我就用了this.$forceUpdate()
代码如下:
<el-upload
action=""
:show-file-list="false"
:http-request="uploadImg"
:before-upload="beforeAvatarUpload">
<img v-if="acinfo.actImg" :src="acinfo.actImg" class="avatar"/>
<i v-else class="el-icon-plus avatar-uploader-icon" style="font-size: 30px"></i>
</el-upload>
//上传方法
uploadImg(param) {
upload(param, (imgUrl) => {
if (imgUrl) {
this.$forceUpdate()
this.acinfo.actImg = imgUrl;
}
})
},
然后就可以显示图片了