vue-axios的使用

我的未来我决定 提交于 2019-12-02 23:40:33
   //get请求
    axios
      .get("json/getDate.json", {
        params: { id: 50 }
      })
      .then(res => {
        console.log(res);
      });
    axios({
      method: "get",
      url: "json/getDate.json",
      params: { id: 10 }
    }).then(res => {
      console.log(res);
    });

    //post请求的格式有
    //application/json:
    //form-data:表单提交(图片上传和文件上传)
    let filter = { name: "55" };
    axios.post("json/postDate.json", filter).then(res => {
      console.log(res);
    });
    //http://localhost:8080/json/postDate.json?goodname=sun
    axios({
      method: "post",
      url: "json/postDate.json",
      data: filter,
      params: { goodname: "sun" }
    }).then(res => {
      console.log(res);
    });

    //form-data请求
    let formData = new FormData();
    for(let key in filter){
        formData.append(key,filter[key])
    }
    axios.post("json/postDate.json",formData).then(res => {
      console.log(res);
    });

    //patch请求
        axios.patch("json/path.json",filter).then(res => {
      console.log(res);
    });
       //put
    axios.put("json/put.json",filter).then(res => {
      console.log(res);
    });
  }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!