<el-form ref="form" :model="form" :rules="rules" size="small" label-width="90px">
<el-upload
class="avatar-uploader"
action='http://192.168.1.143:8090/consulting-file/file/tempSaveFile'
name="multipartFile"
:show-file-list="false"
v-model="form.file.fileId"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload">
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
``` doSubmit() {
this.$refs['form'].validate((valid) => {
if (valid) {
this.loading = true
/* this.form.roles = [] */
const _this = this
commit(this.form.file.fileId).then(res => {
add(this.form).then(res => {
this.resetForm()
this.$notify({
title: '添加成功',
type: 'success',
duration: 2500,
})
this.loading = false
this.$parent.$parent.init()
}).catch(err => {
this.loading = false
console.log(err.response.data.message)
})
}).catch(err => {
this.loading = false
console.log(err.response.data.message)
})
/* this.roleIds.forEach(function(data, index) {
const role = { id: data }
_this.form.roles.push(role)
}) */
/* this.form.accountNumber.password = md5(this.form.accountNumber.password) */
} else {
return false
}
})
},
在dosubmit()里写一个imgurl=''就可以了
是浏览器设置的问题,取不到真正的地址 ,解决方法:
工具 -> Internet选项 -> 安全 -> 自定义级别 -> 找到“其他”中的“将本地文件上载至服务器时包含本地目录路径”,选中“启用”就能解决问题。
以上方法在xp、win7都通用
on-success方法上传成功后 把src绑定的值置空
工具 -> Internet选项 -> 安全 -> 自定义级别 -> 找到“其他”中的“将本地文件上载至服务器时包含本地目录路径”,选中“启用”