首先在router index下配置路由:
import detail from '@/page/datail'
{
path:'/detail/:id',
name:'detail',
component:detail,
},
在path后边缀上/:id就是带参数的路由
在原页面中写入<span @click="routeToDetail">路由跳转</span>
routeToDetail(){
this.$router.push({name: 'detail', params: {id: id}}); }
name为路由的名称,params中为传递的参数,在要跳转的页面中(本例中即detail页面),在created中调用如下的getid方法,即可获得传递的参数。
getid(){
var id = this.$route.params.id // 此处非router
}
即可获得所需参数。