vue-router 页面传参的俩种方法

xiaoxiao2021-02-28  131

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为页面传参的赋值,其他地方可调用。

转载请注明原文地址: https://www.6miu.com/read-17768.html

最新回复(0)