Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js vue路由器将参数路由到组件属性?_Vue.js_Vuejs2_Vue Router - Fatal编程技术网

Vue.js vue路由器将参数路由到组件属性?

Vue.js vue路由器将参数路由到组件属性?,vue.js,vuejs2,vue-router,Vue.js,Vuejs2,Vue Router,我认为这会奏效: { path: '/course/:id', component: Course.extend({ props: { course: params.id } }) }, 遗憾的是,它并没有那么简单(它也不是id)。我该怎么做?(我刚上了一门关于vue的课程,简直不敢相信我记不起来了)因为在中,你必须在路线中设置道具选项,请参见下面的代码以了解它: const User = { props: ['id'], template: '<div>U

我认为这会奏效:

  { path: '/course/:id', component: Course.extend({
    props: { course: params.id }
  }) },
遗憾的是,它并没有那么简单(它也不是
id
)。我该怎么做?(我刚上了一门关于vue的课程,简直不敢相信我记不起来了)

因为在中,你必须在
路线中设置
道具
选项,请参见下面的代码以了解它:

const User = {
  props: ['id'],
  template: '<div>User {{ id }}</div>'
}
const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User, props: true }
  ]
})
const用户={
道具:['id'],
模板:“用户{{id}}”
}
常量路由器=新的VueRouter({
路线:[
{path:'/user/:id',component:user,props:true}
]
})