this.$router.push({name: 'details', params: {'id': 233}})
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
mode: 'history',
routes: [
{
path: '/details',
name: 'details',
component: resolve => require(['../components/details'], resolve)
}
]
})
this.$route.params.id // 233
this.$route.params.id // undefined
console.log(this.$route.params.id + 1)
routes: [
{
path: '/details/:id', // 这里配置的要和你传递的参数名保持一致
name: 'details',
component: resolve => require(['../components/details'], resolve)
}
]
this.$router.push({path: '/details', query: {id: 666}})
this.$route.query.id // 666
官方文档 vue-router