Internal Server Error: /undefined at the end of url for delete request

Internal Server Error: /undefined at the end of url for delete request

在 url 的末尾得到 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/ 但不确定这个 undefined 是从哪里来的。

如有任何帮助,我们将不胜感激。

更新:

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
  }
}

`

谢谢

您正在将带有查询参数的完整 url 传递给您的 axios delete。我认为您只需要删除 id 参数:

export default {
  async delete (url) {
    const response = await http.delete(`${url}`)
    return response
  }
}

只需删除 id 参数,因为 ${id}/ 的计算结果为 undefined/。您根本没有传递任何 id 参数。

最简单:

简直export http