标签:ams query router 获取 页面 component tail log 刷新
1、用name和params传参(参数不会带在地址中,页面刷新参数会丢失)
对应路由配置
{ path: ‘/detail‘, name: ‘detail‘, component: detail }
跳转时传参
this.$router.push({
name: ‘detail‘,// 页面名称
params: {// 要传递的参数
name: ‘张三‘,
}
})
页面中获取参数:
console.log( this.$route.params.name)
对应路由配置:
{
path: ‘/detail‘,
name: ‘detail‘,
component: detail
}
跳转时传参:
this.$router.push({
path: ‘/detail‘,
query: {
name: ‘张三‘
}
})
页面中获取参数:
console.log(this.$route.query.name)
3、在配置时携带参数(带在url地址中,页面刷新不会丢失)
路由配置
{
path: ‘/detail/:name‘,
component: ‘detail‘
}
跳转传参
jump(name) {
this.$router.push({
path: ‘/detail/${name}‘
})
}
页面中获取参数
console.log( this.$route.params.name)
标签:ams query router 获取 页面 component tail log 刷新
原文地址:https://www.cnblogs.com/pyx-blog/p/13214656.html