axios之post提交

axios官网地址:https://github.com/axios/axiosios

post提交到后台须要作相对应的处理git

使用URLSearchParams可让post 数据提交到后台github

对应gitHub上的内容以下:axios

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;
          }
   })
  }
   
 }
相关文章
相关标签/搜索