最佳答案
假设我有这样一个 Vue.js 组件:
var Bar = Vue.extend({
props: ['my-props'],
template: '<p>This is bar!</p>'
});
当 Vue-router 中的某个路由被匹配时,我想使用它:
router.map({
'/bar': {
component: Bar
}
});
通常,为了将‘ myProps’传递给组件,我会这样做:
Vue.component('my-bar', Bar);
以及 html:
<my-bar my-props="hello!"></my-bar>
在这种情况下,当路由匹配时,路由器将自动绘制路由器视图元素中的组件。
我的问题是,在这种情况下,如何将道具传递给组件?