Vue router 1.0 go方法如何传递更多的参数?

环境

  • "vue": "^1.0.14"

  • "vue-router": "0.7.13",

路由1

'/about/:aa': {
      name: 'about',
      component: require('./components/about.vue')
    },

跳转1

  this.$router.go({name: 'about', params: {aa: 11}});

结果1

以下方式,能够使用{{$route.params.aa}}获取到值。

路由2

'/about': {
      name: 'about',
      component: require('./components/about.vue')
    },

跳转2

  this.$router.go({name: 'about', params: {aa: 11}});

结果2

那么{{$route.params.aa}}获取不到值。

query方式能够传递一个对象,但是会拼接在URL上面。

期望

如果我想通过params传递一个对象,应该如何使用?

阅读 3k
2 个回答

绑定params就能够把参数直接传入,还可以绑定自定义事件callback,用于回调。

<router-view :params="params" @callback="callback"></router-view>

似乎vue 1.x对params做了限制 只有路由匹配的上才能拿到params,2.x已经都可以了
暴力点的办法

vue.prototype.xxx = {}
或者在根实例上data里面return一个
extraMsg:{}
在通过this.$root.extraMsg来获取
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题