首页 > 移动平台 > 详细

axios之post提交

时间:2019-09-28 21:02:53      阅读:99      评论:0      收藏:0      [点我收藏+]

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;
          }
   })
  }
   
 }

axios之post提交

原文:https://www.cnblogs.com/sunny-yu/p/11604748.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!