vue多个路由使用同一个页面,通过name判断参数,渲染页面数据
项目中,发现有多个页面的数据内容相同,只是请求数据的参数不同,就可以使用同一个组件来渲染
这里的客户列表 / 我负责的 / 我参与的 都使用同一个组件,不同点在请求数据的参数
可以看到,通过钩子函数,判断路由name,从而修改请求参数,来得到不同的数据内容
这里需要注意三个地方:
1.路由设置
配置路由时,使用相同组件,但是要定义好各自的name
1 {
2 path: "customer_list",
3 component: () => import("@/views/groupManagement/customer_list/index"),
4 name: "customer_list",
5 meta: {
6 title: "customer_list",
7 icon: "",
8 noCache: true
9 }
10 },
11 {
12 path: "my_responsible",
13 component: () => import("@/views/groupManagement/customer_list/index"),
14 name: "my_responsible",
15 meta: {
16 title: "my_responsible",
17 icon: "",
18 noCache: true
19 }
20 },
21 {
22 path: "my_partake",
23 component: () => import("@/views/groupManagement/customer_list/index"),
24 name: "my_partake",
25 meta: {
26 title: "my_partake",
27 icon: "",
28 noCache: true
29 }
30 },
2.钩子函数判断路由name修改参数,或者直接在data申明的时候判断
判断name,修改请求参数
1 created() {
2 if (this.$route.name == "my_partake") {
3 this.filter.is_my = 0;
4 this.filter.is_join = 1;
5 } else if (this.$route.name == "my_responsible") {
6 this.filter.is_my = 1;
7 this.filter.is_join = 0;
8 } else if(this.$route.name == "customer_list") {
9 this.filter.is_my = 0;
10 this.filter.is_join = 0;
11 }
12 this.getTableData();
13 },
1 // 搜索条件
2 filter: {
3 keywords: "",
4 start_date: "",
5 end_date: "",
6 status: "",
7 goods_cat_id: "",
8 type: "plan_name",
9 plan_type: "-1",
10 is_my: this.$route.name == "planList" ? "0" : "1"
11 //这里是判断name修改参数
12 },
3.通过侦听器watch 监听路由,道理同第二步一样,目的也一样
1 watch: {
2 $route(to, from) {
3 this.filter.is_my = "";
4 this.filter.is_join = "";
5 this.table.total = 0;
6 this.table.currentPage = 1;
7 this.table.pageSize = 20;
8 if (to.name == "my_partake") {
9 this.filter.is_my = 0;
10 this.filter.is_join = 1;
11 } else if (to.name == "my_responsible") {
12 this.filter.is_my = 1;
13 this.filter.is_join = 0;
14 } else if(to.name == "customer_list") {
15 this.filter.is_my = 0;
16 this.filter.is_join = 0;
17 }
18 this.getTableData();
19 }
20 },
vue多个路由使用同一个页面,通过name判断参数,渲染页面数据的更多相关文章
- vue多个路由复用同一个组件的跳转问题(this.router.push)
因为router-view传参问题无法解决,比较麻烦. 所以我采取的是@click+this.router.push来跳转 但是现在的问题是跳转后,url改变了,但是页面的数据没有重新渲染,要刷新才可 ...
- for 循环遍历数据,根据不同的条件判断动态渲染页面!
整体的逻辑为:for 循环遍历出数据,在for 循环里判断,根据不同的条件渲染 一.html页面结构 二.css就不再写了 三.JS逻辑代码 var listGroup='' ;k<data.i ...
- 判断AngularJS渲染页面完成
$scope.$on('$viewContentLoaded', function(){ }); // 或者 $scope.$watch('$viewContentLoaded', function( ...
- vue路由参数变化刷新数据
当路由到某个组件时,由于组件会复用,所以生命周期函数不会再次执行, 如果这个组件是模板组件,靠传入不同数据来显示的.那么,可能会发生参数变化了但页面数据却不变化. 问题 假如有个组件 info.vue ...
- Vue编程式路由跳转传递参数
Vue 有时在路由跳转时需要用到一些原页面里的数据,用以下方法: 1.在跳转页的方法里写下query参数 TableChange(scope){ this.$router.push({ path:'d ...
- 解决vue多个路由共用一个页面的问题
在日常的vue开发中我们可能会遇见多个路由需要共用一个页面的需求,特别是当路由是通过动态添加的,不同的路由展示的东西只是数据不同其他没有变化.例如: ? 1 2 3 4 5 6 7 8 9 10 11 ...
- vue 通过 name 和 params 进行调整页面传参刷新参数丢失问题&vue路由可选参数
vue 通过 name 和 params 进行调整页面传参刷新参数丢失问题 router.js: export default new Router({ routes: [ { path: '/', ...
- vue如何配置路由 、获取路由的参数、部分刷新页面、缓存页面
vue如何配置路由 .获取路由的参数.部分刷新页面.缓存页面:http://www.mamicode.com/info-detail-1941546.html vue-router传递参数的几种方式: ...
- Vue 实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案
Vue实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案 by:授客 QQ:1033553122 开发环境 Win 10 Vue 2.9.6 node-v ...
随机推荐
- 【餐厅】 What kind of food would you like to eat tonight?
核心句型 What kind of food would you like to eat tonight? 你今晚想吃哪种菜? What would you like to eat ? 你想吃什么? ...
- 【Spring AOP】AOP介绍(一)
AOP(Aspect Oriented Programming) 面向切面编程,是Spring框架的一个重要组件. AOP应该算是对OOP(面向对象编程)的补充和完善.OOP引入封装.继承.多态等概念 ...
- USACO wormhole
洛谷 P1444 [USACO1.3]虫洞wormhole https://www.luogu.org/problemnew/show/P1444 JDOJ 2386: USACO 2013 Dec ...
- MySql5.7InnoDB全文索引(针对中文搜索)
1.ngram and MeCab full-text parser plugins 全文检索在MySQL里面很早就支持了,只不过一直以来只支持英文.缘由是他从来都使用空格来作为分词的分隔符,而对于中 ...
- odoo fields_view_get
odoo fields_view_get创建动态视图方法 odoo fields_view_get方法是一个比较有用比较灵活的广泛,如果使用得当,可以做到一些常规方法无法实现的功能,本文列举若干种用 ...
- Linux性能优化实战学习笔记:第三十二讲
一.上节总结 专栏更新至今,四大基础模块的第三个模块——文件系统和磁盘 I/O 篇,我们就已经学完了.很开心你还没有掉队,仍然在积极学习思考和实践操作,并且热情地留言与讨论. 今天是性能优化的第四期. ...
- dogcom在openwrt上的使用
前提,先配置并运行mentohust(作为802.1x认证) 1,取得编译完成的可执行文件(可先在虚拟机里测试) 2,上传到路由器 3,把dogcom主程序和配置文件放在/etc/storage/do ...
- Git的学习总结
首先,Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 也是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件. ...
- SQL语句中使用回车换行符
今天发现sql数据库有个图片路径中包含空格,结果在替换和查找时,发现用空格无效,后来经过确认才发现原来是回车换行符引起,从表面看很像空格,实际是回车符,要用char(13)才能进行替换和查找 --查找 ...
- Jenkins使用过程中遇到的问题
1./usr/local/jdk1.8.0_191/ is not a directory on the Jenkins master (but perhaps it exists on some a ...