这是我服务器的响应
{"message":"Resource Created","payload":
[{"id":"5d80270413452b6732fd5217","name":"asdf"}]}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将 设置id为我的状态。
目前正在尝试这个。
axios.post(`http://localhost:8081/companies`, company)
.then(request => request.data.payload.id)
.then(id => {
commit('setCreatedCompanyID', id)
})
Run Code Online (Sandbox Code Playgroud)
我相信错误出在这一行
.then(request => request.data.payload.id)
Run Code Online (Sandbox Code Playgroud)
如何从响应数组中获取第一个 ID?
用于myArray[index]访问数组index的第 -th 元素myArray。例如:
.then(request => request.data.payload[0].id)
Run Code Online (Sandbox Code Playgroud)
演示:
.then(request => request.data.payload[0].id)
Run Code Online (Sandbox Code Playgroud)
axios.get(`https://api.myjson.com/bins/rin05`)
.then(request => request.data.payload[0].id)
.then(console.log)Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4487 次 |
| 最近记录: |