axios之post提交


axios官網地址:https://github.com/axios/axios

post提交到后台需要做相對應的處理

使用URLSearchParams可以讓post 數據提交到后台

對應gitHub上的內容如下:

       In a browser, you can use the URLSearchParams API as follows:

       const params = new URLSearchParams();
        params.append('param1', 'value1');
       params.append('param2', 'value2');
      axios.post('/foo', params);


     post提交之頭像上傳:

      首先先閱讀gitHub上axios關於頭像上傳的介紹

      查看文件examples里面的upload  里面相對應有處理介紹

        首先這有一個demo是簡單的圖片上傳

         <img :src="headImg" alt="">
    <input type="file" id = "head" @change="uploadImg()">

      // 圖片上傳
 uploadImg(){
  //  console.log(document.getElementById('head').files[0])  點取消輸出undefined

  if(document.getElementById('head').files[0]){
         var data = new FormData();
          data.append('headfile', document.getElementById('head').files[0]);
          axios.post("輸入上傳接口地址",data).then(rest=>{
          console.log(rest);
          if(rest.data.code===200){
            this.headImg = rest.data.data.msbox;
          }
   })
  }
   
 }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM