zoukankan      html  css  js  c++  java
  • vue-axios的使用

       //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);
        });
      }
  • 相关阅读:
    flex居中
    flex
    js将接口返回的数据序列化
    用javascript替换URL中的参数值
    object遍历删除空值
    node代理服务器
    随机生成id
    正则之特殊字符
    H5项目常见问题及注意事项
    node编译C++,比如安装node-gyp失败的问题
  • 原文地址:https://www.cnblogs.com/lvlvlv/p/11767689.html
Copyright © 2011-2022 走看看