day67_10_11
2024-08-29 22:01:37
一。路由跳转
在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;
}
最新文章
- Linux常见练习题
- redis.conf 配置详解 (转)
- 让HTML5语义化标签兼容IE浏览器
- EF4 Code First和EF6 Code First链接mysql的方法
- 源码编译基于Android平台的XBMC笔记
- Python IDE的选择和安装
- ul和li实现分两列(多列)布局显示
- JAVA描述的简单ORM框架
- OO第一阶段总结
- 基于Jmeter的thrift-RPC接口测试
- Android 杂谈---ListView 之BaseAdapter
- 82、iOS 基本算法
- Log4j2配置与使用
- steps/train_sat.sh
- each遍历
- ACM知识点分类
- kubernetes集群搭建(9):docker 镜像的导入与导出
- 《Linux内核设计与实现》读书笔记 1&;2
- Windows NTFS 符号链接 与 Linux 软连接
- Liferay-Activiti 功能介绍 (新版Liferay7基本特性)
热门文章
- 201871010109-胡欢欢《面向对象程序设计(java)》第十六周学习总结
- acwing 23. 矩阵中的路径
- Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题
- Salesforce 开发整理(一)测试类最佳实践
- JDBC释放数据库连接
- java循环定时器@Scheduled的使用
- jQuery 源码分析(十七) 事件系统模块 实例方法和便捷方法 详解
- 【IDEA】(2)---MAC代码模版
- 帝国CMS QQ登陆接口插件 适用于所有帝国7.2版本
- Python打包成exe文件很难?一分钟即可学会,并添加图标!