vue通过路由传值

1、配置路由 通过routes
export default new Router({
  routes: [
    {
      path: '/test',
      name: 'test', //必须添加name,否则params无法识别
      component: test
    }
  ]
})
2、传递参数 通过$router
this.$router.push({
        name: 'test',
       params: {
           page: '1'
     }
 })
3、接收参数 通过$route
created() {
		this.getRouterData()
},
methods: {
		// 接受路由传参
		getRouterData() {
	      this.page = this.$route.params.page;
	    }
}

猜你喜欢

转载自blog.csdn.net/Lycoriy/article/details/104040690