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

来源:互联网 发布:阿里云研究报告 编辑:程序博客网 时间:2024/05/16 02:01

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

原创粉丝点击