一。路由跳转

  在vue中,路由条状有很多种。

  其中有点击事件触发的路由跳转:

this.$router.push('/course');

  和通过名字跳转的:

this.$router.push({name: course});

  对history操作的go语法,可以调节回退页面:

this.$router.go(-1);
this.$router.go(1);

  在router-link中,也有可以跳转路由的方法:

<router-link to="/course">课程页</router-link>

  跳转字典对象的:

<router-link :to="{name: 'course'}">课程页</router-link>

二。路由传参。

  如果需要传递参数给各个页面。反馈不同的页面,需要传毒有参路由:

  第一种。

  通过:id的有参参数传递给路由:

  router.js

routes: [
// ...
{
path: '/course/:id/detail',
name: 'course-detail',
component: CourseDetail
},
]

  跳转。vue

<template>
<router-link :to="`/course/${course.id}/detail`">{{ course.name }}</router-link>
</template>
<script>
// ...
goDetail() {
this.$router.push(`/course/${this.course.id}/detail`);
}
</script>

  接受vue:

created() {
let id = this.$route.params.id;
}

  第二种

  在push种有params传递参数,也可以通过query传递参数,这里通过router-link传递字典对象。

  router.js

routes: [
// ...
{
path: '/course/detail',
name: 'course-detail',
component: CourseDetail
},
]

  跳转。vue

<template>
<router-link :to="{
name: 'course-detail',
query: {id: course.id}
}">{{ course.name }}</router-link>
</template>
<script>
// ...
goDetail() {
this.$router.push({
name: 'course-detail',
query: {
id: this.course.id
}
});
}
</script>

  接受。vue

created() {
let id = this.$route.query.id;
}

最新文章

  1. Linux常见练习题
  2. redis.conf 配置详解 (转)
  3. 让HTML5语义化标签兼容IE浏览器
  4. EF4 Code First和EF6 Code First链接mysql的方法
  5. 源码编译基于Android平台的XBMC笔记
  6. Python IDE的选择和安装
  7. ul和li实现分两列(多列)布局显示
  8. JAVA描述的简单ORM框架
  9. OO第一阶段总结
  10. 基于Jmeter的thrift-RPC接口测试
  11. Android 杂谈---ListView 之BaseAdapter
  12. 82、iOS 基本算法
  13. Log4j2配置与使用
  14. steps/train_sat.sh
  15. each遍历
  16. ACM知识点分类
  17. kubernetes集群搭建(9):docker 镜像的导入与导出
  18. 《Linux内核设计与实现》读书笔记 1&amp;2
  19. Windows NTFS 符号链接 与 Linux 软连接
  20. Liferay-Activiti 功能介绍 (新版Liferay7基本特性)

热门文章

  1. 201871010109-胡欢欢《面向对象程序设计(java)》第十六周学习总结
  2. acwing 23. 矩阵中的路径
  3. Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题
  4. Salesforce 开发整理(一)测试类最佳实践
  5. JDBC释放数据库连接
  6. java循环定时器@Scheduled的使用
  7. jQuery 源码分析(十七) 事件系统模块 实例方法和便捷方法 详解
  8. 【IDEA】(2)---MAC代码模版
  9. 帝国CMS QQ登陆接口插件 适用于所有帝国7.2版本
  10. Python打包成exe文件很难?一分钟即可学会,并添加图标!