我正在尝试将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形成此请求?
答案 0 :(得分:0)
也许是因为你的 this。$ route.params.id 为null或未定义。