首页 > 解决方案 > 将多个参数传递给 POST - Axios

问题描述

我正在尝试传递一个team对象league_id整数作为参数传递给我的发布请求。但我似乎只能让团队参数通过......

这是我正在使用的内容:

onSubmit: function () {
    axios.post('/api/v1/teams', {team: {name: this.$refs.team_name.value}, league_id: this.$route.params.id}, {
      headers: {
        Authorization: "Bearer "+localStorage.getItem('token')
      }
    }).then(response => {
      this.$router.push('/')
    }).catch(error => {
      this.$router.push('/create_team')
    })
  }

这是我的服务器收到的:

%{"team" => %{"name" => "face"}}

我希望它看起来像这样:

%{"team" => %{"name" => "face"}, "league_id" => 15}

如何使用 Axios 形成此请求?

标签: javascriptvue.jsaxios

解决方案


也许是因为您的this.$route.params.id为空或未定义。


推荐阅读