vue axios 表單提交上傳圖片的執行個體,

來源:互聯網
上載者:User

vue axios 表單提交上傳圖片的執行個體,

項目中用的element 的架構,然後在項目有一個添加資料需求是圖片可上傳,也可不上傳,

然後問題就是element 中的上傳控制項在沒有圖片的時候是不會觸發提交的,但介面寫的是有file的  multipart/form-data    接收模式

所有只能自己另個模仿一個表單上傳

<input class="file" name="file" type="file" accept="image/png,image/gif,image/jpeg" @change="update"/> 
let file = e.target.files[0];       let param = new FormData(); //建立form對象    param.append('file',file,file.name);//通過append向form對象添加資料    param.append('chunk','0');//添加form表單中其他資料       let config = {    headers:{'Content-Type':'multipart/form-data'}    }; //添加要求標頭    this.axios.post('http://upload.qiniu.com/',param,config)    .then(response=>{    console.log(response.data);    }) 

以上這篇vue axios 表單提交上傳圖片的執行個體就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.