iview的Upload有before-upload方法,参数file里没有文件路径?
<Upload
ref="upload"
:show-upload-list="true"
:format="['jpg', 'jpeg', 'png']"
:max-size="2048"
:before-upload="handleBeforeUpload"
:on-success = "onSuccess"
:on-progress="onProgress"
multiple
type="drag"
:action= "baseURL2 + '/api/basic/uploadDishImg'"
:data= "{ dishCode: this.form.dishCode }"
style="display: inline-block; width: 204px"
>
<div class="upload-img">
<Icon v-if="!photo" type="ios-add" size="30" />
<div v-if="!photo" class="upload-img-label">
上传图片
</div>
<img v-else :src="photo" alt="" style="width:100%;height:100%">
</div>
</Upload>
handleBeforeUpload(file) {
const _this = this
const reader = new FileReader()
reader.readAsDataURL(file);
reader.onload = function (e) {
// 文件base64
const fileBase64 = this.result
_this.photo = fileBase64
}
},