vue-router 页面传参的俩种方法
a页面传参到b页面routes页面代码let routes = [ { { path: '/a', component: A, name: 'a', }, { path: '/b/:Id', component:B, name: 'b', },}a页面代码this.$router.pu
a页面传参到b页面
routes页面代码
let routes = [
{
{
path: '/a',
component: A,
name: 'a',
},
{
path: '/b/:Id',
component:B,
name: 'b',
},
}
a页面代码
this.$router.push({ name: 'b', params: { id: Id}});
this.$router.replace({ name: 'b', params: { id: Id}});
(其中name的值对应路由里面的name的值,params为页面传的值,传给路由接收)
b页面代码
(当 $route发生变化时再次赋值listKeyword )
watch: {
'$route': function () {
this.listKeyword = this.$route.params.id; (id为接收路由传过来的id)
}
},
(页面加载时赋值listKeyword )
mounted() {
this.listKeyword = this.$route.params.id;
},
this.listKeyword为页面传参的赋值,其他地方可调用。
更多推荐
所有评论(0)