vue+vant 上傳圖片需要注意的地方
<van-uploader v-model='fileList' multiple :after-read='afterRead' :max-count='1' />1:上傳文件流,提交的模式 肯定得 form-data模式
afterRead(file){console.log(file); //控制臺(tái)可以看見圖片信息 if(this.fileList.length > 1){ this.fileList.splice(1); this.$msg({ text:’只能選擇這么多!’, type:’info’ }) return false; } let Files = this.Files; Files.push(file.file); },3:vue 里面axios 攔截處理 因?yàn)樯蟼髂J奖仨毷莊rom-data 所以就要設(shè)置 config.headers[’Content-Type’] = ’multipart/form-data’;
//http request 攔截器axios.interceptors.request.use((config) => { if (config.method === ’post’) { if( config.data && !config.data.i ){ config.headers[’Content-Type’] = ’multipart/form-data’; }else{ config.data = Qs.stringify(config.data); } // if ( config.data ){ // if ( config.data.i === undefined ){ // config.headers[’Content-Type’] = ’multipart/form-data’; // }else{ // config.data = Qs.stringify(config.data); // } // } } return config;}, (error) => { return Promise.reject(error);})4:就是上次圖片前端做的處理需要用到 new FormData() 做出處理,因?yàn)槭俏募?,直接打印是看不出?lái)的詳情去看官網(wǎng)new FormData()。
WineOrder(){ console.log(this.Files) this.disabled = true; const data = new FormData(); const USER = JSON.parse(sessionStorage.getItem(’USER’)); data.append(’i’,USER.uniacid); data.append(’token’,USER.token); data.append(’bid’,USER.bid); data.append(’roomid’,this.roomid); data.append(’booker’,this.dingName); data.append(’guestname’,this.userName); data.append(’type’,this.type); data.append(’tel’,this.phone); data.append(’endtime’,this.date); data.append(’file’,this.Files[0]); data.append(’goodsinfo’,JSON.stringify(this.savewineList)); WineOrder(data).then((e)=>{if( e.code == 0 ){ this.disabled = false; e.totalmoney = ’’; var c ={ Topic:'', data:e, type:’Savewine’ } return; setTimeout(() => { window.location.href='http://www.lshqa.cn/bcjs/setterOrder?c=' rel='external nofollow' +JSON.stringify(c); }, 1500);}else{ this.disabled = false; this.$msg({ text:e.msg, type:’info’ })} }) },
效果圖
剩下的就交給后端處理就行了,到這里就完全可以了
以上就是vue+vant 上傳圖片需要注意的地方的詳細(xì)內(nèi)容,更多關(guān)于vue+vant 上傳圖片的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. ASP常用日期格式化函數(shù) FormatDate()2. chat.asp聊天程序的編寫方法3. CSS 使用Sprites技術(shù)實(shí)現(xiàn)圓角效果4. phpstudy apache開啟ssi使用詳解5. 詳解瀏覽器的緩存機(jī)制6. ASP中if語(yǔ)句、select 、while循環(huán)的使用方法7. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?8. HTML中的XML數(shù)據(jù)島記錄編輯與添加9. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法10. 推薦一個(gè)好看Table表格的css樣式代碼詳解
