使用vue-router
包,很容易match dynamic segments :
router.map({
'/user/:username': {
component: {
template: '<p>username is {{$route.params.username}}</p>'
}
}
})
但是,我不知道如何使用组件方法的值,例如
router.map({
'/user/:username': {
component: {
ready: function() {
// How to access the param here?
alert($route.params.username);
}
}
}
})
如何在组件方法中访问匹配的段?
最佳答案
和你发的差不多
// inside your component
this.$route.params.username
关键是在模板中你不需要引用this
范围,但在方法中你必须使用它
关于vue.js - 如何匹配 vue-router 路由并在组件函数中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37734958/