javascript - vue路由中怎么传入数据?就是new Vue里面的data
阿神
阿神 2017-04-11 12:48:14
[JavaScript讨论组]

如题Italic

阿神
阿神

闭关修行中......

全部回复(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...

PHPz

动态路由,然后用$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();
}
ringa_lee

在router路由上定义

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

在跳转的地方

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

新界面接收

this.$route.params.classId
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号