【发布时间】:2018-11-20 13:12:46
【问题描述】:
我正在使用 vue-router 运行 Vue.js,并尝试将参数传递给我的模板。
这是我的路线:
{ path: '/car/:id', component: car, props: true },
这是我的模板Car.vue:
<template>
<h2>{{ id }}</h2>
</template>
<script>
export default {
props: ['id']
},
methods: {
getCar: function () {
axios.get('http://my-api/car/' + id)
.then((response) => {
this.car = response.data
})
.catch((error) => {
console.log(error)
})
}
</script>
我收到了错误:
✘ http://eslint.org/docs/rules/no-undef 'id' is not defined
但是id显示在h2中,但没有在api调用中使用。
【问题讨论】:
-
你应该使用
this.id而不是id访问道具
标签: javascript vue.js vuejs2