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