项目中,发现有多个页面的数据内容相同,只是请求数据的参数不同,就可以使用同一个组件来渲染

  这里的客户列表 / 我负责的 / 我参与的 都使用同一个组件,不同点在请求数据的参数

  可以看到,通过钩子函数,判断路由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判断参数,渲染页面数据的更多相关文章

  1. vue多个路由复用同一个组件的跳转问题(this.router.push)

    因为router-view传参问题无法解决,比较麻烦. 所以我采取的是@click+this.router.push来跳转 但是现在的问题是跳转后,url改变了,但是页面的数据没有重新渲染,要刷新才可 ...

  2. for 循环遍历数据,根据不同的条件判断动态渲染页面!

    整体的逻辑为:for 循环遍历出数据,在for 循环里判断,根据不同的条件渲染 一.html页面结构 二.css就不再写了 三.JS逻辑代码 var listGroup='' ;k<data.i ...

  3. 判断AngularJS渲染页面完成

    $scope.$on('$viewContentLoaded', function(){ }); // 或者 $scope.$watch('$viewContentLoaded', function( ...

  4. vue路由参数变化刷新数据

    当路由到某个组件时,由于组件会复用,所以生命周期函数不会再次执行, 如果这个组件是模板组件,靠传入不同数据来显示的.那么,可能会发生参数变化了但页面数据却不变化. 问题 假如有个组件 info.vue ...

  5. Vue编程式路由跳转传递参数

    Vue 有时在路由跳转时需要用到一些原页面里的数据,用以下方法: 1.在跳转页的方法里写下query参数 TableChange(scope){ this.$router.push({ path:'d ...

  6. 解决vue多个路由共用一个页面的问题

    在日常的vue开发中我们可能会遇见多个路由需要共用一个页面的需求,特别是当路由是通过动态添加的,不同的路由展示的东西只是数据不同其他没有变化.例如: ? 1 2 3 4 5 6 7 8 9 10 11 ...

  7. vue 通过 name 和 params 进行调整页面传参刷新参数丢失问题&vue路由可选参数

    vue  通过 name 和 params 进行调整页面传参刷新参数丢失问题 router.js: export default new Router({ routes: [ { path: '/', ...

  8. vue如何配置路由 、获取路由的参数、部分刷新页面、缓存页面

    vue如何配置路由 .获取路由的参数.部分刷新页面.缓存页面:http://www.mamicode.com/info-detail-1941546.html vue-router传递参数的几种方式: ...

  9. Vue 实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案

    Vue实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案   by:授客 QQ:1033553122   开发环境   Win 10   Vue 2.9.6   node-v ...

随机推荐

  1. Lp距离, L1范数, 和L2范数(转载)

    范式可以理解成距离 转载自: https://blog.csdn.net/hanhuili/article/details/52079590 内容如下: 由此可见,L2其实就是欧式距离.工程上,往往不 ...

  2. XLA

    原 TensorFlow技术内幕(七):模型优化之XLA(上) 2018年06月13日 14:53:49 jony0917 阅读数 5513   版权声明:本文为博主原创文章,遵循CC 4.0 by- ...

  3. VIJOS-P1078 松鼠吃果子

    洛谷 P2069 松鼠吃果子 https://www.luogu.org/problemnew/show/P2069 JDOJ 1256: VIJOS-P1078 松鼠吃果子 https://neoo ...

  4. C# 一般处理程序

    public class Three : IHttpHandler{ public void ProcessRequest(HttpContext context) { context.Respons ...

  5. MySQL中DELETE子句与TRUNCATE TABLE语句的区别

    TRUNCATE语句删除表数据的语法格式:即,table 这个词可要,可不要 TRUNCATE TABLE 表名; TRUNCATE 表名; 1,使用truncate语句后,表中的auto_incre ...

  6. 跨交换机VLAN之间的通信(基于Cisco模拟器)

    实验要求: 拓扑结构如下 1.交换机2台:主机4台:网线若干. 2.把主机.交换机进行互联. 3.给2台交换机重命名为A.B. 4.设置2台交换机及主机的ip.注意IP要不冲突 5.在2台交换机上分别 ...

  7. JS通过指定大小来压缩图片

    安装: npm i image-conversion --save 引入: <script src="https://cdn.jsdelivr.net/gh/WangYuLue/ima ...

  8. Linux的开机启动流程

    Linux的开机启动流程 1.开机BIOS自检                                             --> 检查CPU,硬盘等硬件信息 2.MBR[Major ...

  9. ORB-SLAM2初步

    一.ORB-SLAM简介 最近开始入坑SLAM,经过简单调研,各位大咖认为,目前最优秀的视觉SLAM系统是ORB-SLAM2,因此对ORB-SLAM2进行了学习. ORB-SLAM2是2015年提出的 ...

  10. [LeetCode] 236. Lowest Common Ancestor of a Binary Tree 二叉树的最小共同父节点

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...