5 个回答
const a = {
  b:1,
  c:2
}

new Vue({
    data: a
})

不知道你要传入什么data,不过你可以试试用beforeRouteEnter钩子,这时机应该是你想要的:

beforeRouteEnter (to, from, next) {
  next(vm => {
    // 通过 `vm` 访问组件实例
  })
}

详情请看文档

你可能需要动态路由设置?
你这问题描述太抽象只能猜测,有了动态路由你就可以愉快的在<router-link :to="{path: '/'}"></router-link>中拼接路径了,祝你好运

https://router.vuejs.org/zh-c...

动态路由,然后用$route.params去获取路由对象里的信息
详情可以去看vue router的官方文档
下面是我最近写的例子
route.js

export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: index
    },
    {
      path: '/list/:category',
      name: "list",
      component: list,
      meta: { id: 'list-kind' }
    }
  ]
})

parent.vue

<router-link :to="{ path: './list/learn'}" tag="section" class="item">
    <img src="../assets/h5_icon_1.png" alt="Subject Learn">
    <p>It is a learning fairyland for Chinese learners</p>
</router-link>

child.vue

created(){
  this.fetch();
  this.title = this.$route.params.category.toUpperCase();
}

在router路由上定义

{ path: 'courseContent/:lassId',name:'courseContent', component: CourseContent }

在跳转的地方

this.$router.replace({name:'electiveCourse',params:{classId:this.classId}});

新界面接收

this.$route.params.classId
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题