【发布时间】:2019-08-31 11:45:17
【问题描述】:
在网址末尾获取undefined/,似乎无法找出原因。
使用 vuejs、vuex 和 bootstrap-vue
` HTML:
<template slot="time" slot-scope="row">
<b-button @click="deleteTime(row.value.id)">
Delete
</b-button>
</template>
`
方法: `
deleteTime (id) {
this.$store.dispatch('deleteTime', id)
}
`
Action.vue: `
async deleteTime ({ commit, state }, time) {
commit('SET_LOADING', true)
const id = state.route.params.pageId
await api.deleteTime(id, time)
commit('SET_LOADING', false)
}
`
api.js:
`
let deleteTime = '/api/apps/:id/content/time/?id=:timeId'
async deleteTime (id, time) {
const url = deleteTime.replace(':id', id).replace(':timeId', time)
return http.delete(url)
}
`
我得到了这个http://127.0.0.0:8000/api/apps/1/content/time/?id=10undefined/,但不确定这个未定义来自哪里。
任何帮助将不胜感激。
更新:
http.delete 模块: `
import axios from 'axios'
const http = axios.create({
xsrfCookieName: 'csrftoken',
xsrfHeaderName: 'X-CSRFToken'
})
export default {
async delete (url, id) {
const response = await http.delete(`${url}${id}/`)
return response
}
}
`
谢谢
【问题讨论】:
-
在方法中放置一个
console.log(id),看id是否正确。然后在 Action.vue 和 api.js 中。 -
@echefede 请检查。我已经更新了控制台中方法、操作和 api 的响应
-
你能分享你的http模块吗?
-
我假设您要求堆栈跟踪。不幸的是,我不能在这里粘贴它,因为它是一个企业应用程序。但是在“预览”下的“网络”选项卡中查看此输出
ValueError at /api/apps/1/content/time/ invalid literal for int() with base 10: '10undefined/'唯一的问题是我在 url 中附加了未定义。但我似乎确实在 url 中获得了所有必需的值 -
不,我问的是
http.delete()方法。你用的是 axios 还是什么库?也许你在配置中有一些东西。
标签: vue.js vuex bootstrap-vue