【发布时间】:2019-03-20 14:53:41
【问题描述】:
我正在关注a tutorial,但带有参数的路径不起作用。
data() {
return {
id: this.$route.params.id,
element: {
title: '',
description: '',
}
}
},
methods: {
getBook() {
const path = 'http://127.0.0.1:8000/api/v1/books/${this.id}/'
axios.get(path).then((response) => {
this.element.title = response.data.title
this.element.description = response.data.description
})
.catch((error) => {
console.log(error)
})
},
created() {
this.getBook()
}
在控制台中:
"GET /api/v1/books/$%7Bthis.id%7D/ HTTP/1.1" 404 2410
我所做的到底有什么问题?
【问题讨论】:
-
使用
`http://127.0.0.1:8000/api/v1/books/${this.id}`(反引号),而不是''(单引号)。 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…