zoukankan      html  css  js  c++  java
  • axios中Post请求的两种区别

    一、axios   post请求ashx

    一般处理程序(ashx)的好处就是容易上手,直接按住写就行了,但是需要对提供的参数处理一下,不然后端接收不到

             var params={
                  user:this.yhm,
                  pwd:this.$md5(this.pwd).toUpperCase(),
              };
    //Post方法的封装
          axiosPost:function(url,params){
              return new Promise((resolve, reject) => {
                      this.$axios({
                      url: url,
                      method: 'post',
                      data: params,
                      transformRequest: [function(data) {
                          let ret = ''
                          for(let it in data) {
                              ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                          }
                          console.log(ret)
                          return ret
                      }],
                      headers: {
                          'Content-Type':'application/json'
                      }
                  })
                  .then(res=>{
                      resolve(res.data);
                  })
              });
          },

    二、axios POST请求webapi

    这里的webapi我是使用的 .net core3.1 webapi,有控制器、路由等很是好用,post时参数是json格式的,所以在vue中就不需要再对参数进行转换了

     //Post方法的封装
          axiosPost:function(url,params){
              return new Promise((resolve, reject) => {
                      this.$axios({
                      url: url,
                      method: 'post',
                      data: params,
                      // transformRequest: [function(data) {
                      //     let ret = ''
                      //     for(let it in data) {
                      //         ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                      //     }
                      //     console.log(ret)
                      //     return ret
                      // }],
                      headers: {
                          'Content-Type':'application/json'
                      }
                  })
                  .then(res=>{
                      resolve(res.data);
                  })
              });
          },
  • 相关阅读:
    2. Add Two Numbers
    1. Two Sum
    leetcode 213. 打家劫舍 II JAVA
    leetcode 48. 旋转图像 java
    leetcode 45. 跳跃游戏 II JAVA
    leetcode 42. 接雨水 JAVA
    40. 组合总和 II leetcode JAVA
    24. 两两交换链表中的节点 leetcode
    1002. 查找常用字符 leecode
    leetcode 23. 合并K个排序链表 JAVA
  • 原文地址:https://www.cnblogs.com/wjbych/p/12892864.html
Copyright © 2011-2022 走看看