• 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);
                  })
              });
          },
  • 相关阅读:
    python 元组操作
    python安装(python2.7)
    0、
    1、Centos 7 系统的初化始配置
    C# 6.0新特性
    ios学习之路
    Can 't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock '(2) ;
    px,em,rem,vw单位在网页和移动端的应用
    html5shiv.js和respond.min.js
    display:inline-block间隙问题
  • 原文地址:https://www.cnblogs.com/wjbych/p/12892864.html
Copyright © 2020-2023  润新知