拦截器
axios.interceptors.request.use((config)=>{ this.isShow = true; return config; }, function (error) { return Promise.reject(error);});<van-overlay :show="isShow"> <div class="wrapper" style="display: flex; align-items: center; justify-content: center; height: 100%;" @click.stop> <van-loading size="24px">上传中...</van-loading> </div></van-overlay>new Vue({ el: '#app', data: { has_file: true, isShow: false, }});
通用
axios({ method: 'put', url: '{:url("/h5/user/")}{$item.id}', data: this.request_data, }) .then(res => { if(res.data.code === 0){ vant.Toast(res.data.msg); setTimeout(()=>{ window.location.href = '/h5/user' },1000) }else{ vant.Toast(res.data.msg) } }) .catch(error => { vant.Toast(error);})
上传文件
afterRead(file){ let data = new FormData() data.append('file', file.file) data.append('uploadType','image') axios({ method: 'post', url: '{:url("/h5/resource/website")}', data: data, headers: { 'Content-Type': 'multipart/form-data' } }).then(res => { if(res.data.code === 0){ this.requestData.imgs.push(res.data.data.key) }else{ vant.Toast(res.data.msg) } }).catch(error => { vant.Toast(error); }).finally(res => { this.isShowLoading = false this.isShowOverlay = false })}