vue.js - Vue JS:从对象发送 axios 发布数据
问题描述
我需要将我的 JSON 设置为变量,因为我在 2 个地方使用它,即
let data = {
"test": "hello",
"test2": "hello2
}
axios.post('/route', {
data
})
.then((response) => {
this.$emit('anotherFunction', data);
})
我得到一个400
回复,然后当我检查网络请求时,有效负载是:"{data: {"test": "hello", "test2": "hello2"}}"
这是有道理的,但是如果没有 JSON 的data
一部分,我怎么能拥有它呢?
解决方案
你应该data
像这样通过:
let data = {
"test": "hello",
"test2": "hello2
}
axios.post('/route', data)
.then((response) => {
this.$emit('anotherFunction', data);
})
推荐阅读
- python - 在熊猫中将毫秒设置为小时,最长 24 小时
- amazon-web-services - 查询以查找给定行或空行的第一个条目
- android - ViewPager 中 Fragment 中的 OptionsMenu 在显示子 DialogFragment 后冻结
- c - 添加两个结构数组的元素 C
- php - Logic error with Datetime->modify in Symfony entity
- php - Finding duplicates and appending arrays to an array with millions of arrays
- angular - Angular: Multiple nested FormGroups in Component
- oracle - PL/SQL如何调用这个函数
- python - 两个连接的两个数据框如何只有一个相同的列
- json - 如何使用超链接 C# 从复杂的 json 中获取价值