javascript - 将多个参数传递给 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 形成此请求?
解决方案
也许是因为您的this.$route.params.id为空或未定义。
推荐阅读
- javascript - 使用 jsfuck 将带有一个参数的函数传递给 array.map
- gitlab - Gitlab但没有“设置->应用程序”菜单
- docker - Gitlab 在 docker login 和 test 容器中的 CI docker
- google-cloud-firestore - 克隆 Google 的 github 存储库后出现 Stripe 秘密错误
- pyspark - Pyspark:- 获取任何类型的大文件(1gb)的行值,其列值为“False”而没有 OOM 错误
- javascript - 如何使用渲染道具和设计库将 Formik ErrorMessage 与 formik 一起正确使用?
- java - 将列表对象与其他对象排序
- java - 确保所有线程更新 Java 映射中的单个条目
- javascript - 无法使用 Array.sort 在 JavaScript 中实现正确的排序
- mysql - rails - 我错误地运行了“rake db:drop”。我怎样才能恢复我的所有数据?