时间:2021-03-16 10:21:25 | 栏目:vue | 点击:次
<van-uploader v-model="fileList" multiple :after-read="afterRead" :max-count="1" />
afterRead(file){ console.log(file); //控制台可以看见图片信息 if(this.fileList.length > 1){ this.fileList.splice(1); this.$msg({ text:'只能选择这么多!', type:'info' }) return false; } let Files = this.Files; Files.push(file.file); },
//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); })
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="setterOrder?c=" rel="external nofollow" +JSON.stringify(c); }, 1500); }else{ this.disabled = false; this.$msg({ text:e.msg, type:'info' }) } }) },
效果图
剩下的就交给后端处理就行了,到这里就完全可以了