zoukankan      html  css  js  c++  java
  • Vue axios post 传参数,后台接收不到为 null

    由于axios默认发送数据时,数据格式是Request Payload,而并非我们常用的Form Data格式,后端未必能正常获取到,所以在发送之前,需要使用qs模块对其进行处理。
    cnmp install qs --save

    在main.js 中添加

    // The Vue build version to load with the `import` command
    // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    import Vue from 'vue'
    import VueRouter from 'vue-router'
    import router from './router'
    
    import qs from 'qs'
    //定义全局变量
    Vue.prototype.$qs = qs
    var axios = require('axios')
    axios.defaults.baseURL = 'http://localhost:8888/api'
    axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
    //将API方法绑定到全局
    Vue.prototype.$axios = axios
    
    // 导入 ElementUI
    import ElementUI from 'element-ui'
    import 'element-ui/lib/theme-chalk/index.css'
    
    //导入Vuex
    import Vuex from 'vuex'
    
    import App from './App'
    
    
    // 安装路由
    Vue.use(VueRouter);
    
    // 安装 ElementUI
    Vue.use(ElementUI);
    
    //安装 Vuex
    
    Vue.use(Vuex);
    
    new Vue({
      el: '#app',
      // 启用路由
      router,
      // 启用 ElementUI
      render: h => h(App)
    });
    
    
    
     this.$axios.post(
                  '/getTableUserData',
                  this.$qs.stringify({
                      currentPage:this.currentPage,
                      pagesize:this.pagesize
                  }),
                  )
    
  • 相关阅读:
    分治策略
    uva 11424
    lightoj 1214
    lightoj 1282 && uva 11029
    lightoj 1341
    zoj 2369 Two Cylinders
    几种素数筛法
    lightoj 1245
    hdoj 1299 Diophantus of Alexandria
    求前n项正整数的倒数和
  • 原文地址:https://www.cnblogs.com/lick468/p/10984700.html
Copyright © 2011-2022 走看看