Vue-cli中axios传参的方式以及后端取的方式

一.传参

  • params是添加到url的请求字符串中的,用于get请求。
  • data是添加到请求体(body)中的, 用于post请求。

首先现在main.js进行配置

import axios from 'axios'
Vue.prototype.$axios = axios;

如:get请求

<script>
    ......
    事件的函数() {
     this.$axios({
                    url: xxxxx
                    method: 'get',
                    params: {
                        变量名: 变量值
                    }
                }).then(response => {请求成功逻辑代码})..catch(error => {请求失败逻辑代码})
    }
    ........
</script>

如:post请求

<script>
    ......
    事件的函数() {
     this.$axios({
                    url: xxxxx
                    method: 'post',
                    data: {
                        变量名: 变量值
                    }
                }).then(response => {请求成功逻辑代码})..catch(error => {请求失败逻辑代码})
    }
    ........
</script>

二.后台获取

如果是params传参后台取request.GET或者request.query_params

如果是data传参后台取request.data

相关文章:

  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-04-26
  • 2022-12-23
相关资源
相似解决方案