AntdV Upload組件customRequest怎么自定義上傳方法?下面本篇文章給大家介紹一下Ant Design Vue 的Upload 組件customRequest自定義上傳方法,希望對大家有所幫助!

customRequest 可以自定義自己的上傳方法
需求場景
后臺管理系統,UI框架是Ant Design of Vue上傳圖片用的是Upload組件。
需求描述:上傳圖片,轉為base64
實現方法
API方法中,有一個自定義上傳行為的方法,通過覆蓋默認的上傳行為,可以自定義自己的上傳實現
customRequest自定義上傳方法
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="照片"> <a-upload v-decorator="['zp', validatorRules.zp]" listType="picture-card" class="avatar-uploader" :showUploadList="false" :beforeUpload="beforeUpload" :customRequest="selfUpload" > <img v-if="picUrl" :src="getAvatarView()" alt="頭像" style="height:104px;max-width:300px"/> <div v-else> <a-icon :type="uploadLoading ? 'loading' : 'plus'" /> <div class="ant-upload-text">上傳</div> </div> </a-upload> </a-form-item>
上傳的圖片轉為base64
//對上傳的文件處理 selfUpload ({ action, file, onSuccess, onError, onProgress }) {      console.log(file, 'action, file');      const base64 = new Promise(resolve => {          const fileReader = new FileReader();          fileReader.readAsDataURL(file);          fileReader.onload = () => {               resolve(fileReader.result);               // this.formImg = fileReader.result;           }       }); }
【
站長資訊網