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 ...
随机推荐
- No archetypes currently available. The archetype list will refresh when the indexes finish updating
配置方法: 1. 在卡住的而画面点击"config" 2. 点击"Add remote catalog", 然后设置华为云的maven仓库地址, 然后点击&qu ...
- 搭建pikachu平台及暴力破解
一.先将Pikachu文件放在网站根目录下 二.修改pikachu网站的配置文件 inc/config.inc.php define('DBUSER', 'user'); define('DBPW' ...
- http协议里定义的四种常见数据的post方法
原文 https://blog.csdn.net/charlene0824/article/details/51199292 关于http协议里定义的四种常见数据的post方法,分别是: applic ...
- Linux性能优化实战学习笔记:第三十四讲
一.上节回顾 上一节,我带你学习了 Linux 网络的基础原理.简单回顾一下,Linux 网络根据 TCP/IP模型,构建其网络协议栈.TCP/IP 模型由应用层.传输层.网络层.网络接口层等四层组成 ...
- Linux性能优化实战学习笔记:第四十二讲
一.上节回顾 上一节,我们学习了 NAT 的原理,明白了如何在 Linux 中管理 NAT 规则.先来简单复习一下. NAT 技术能够重写 IP 数据包的源 IP 或目的 IP,所以普遍用来解决公网 ...
- [LeetCode] 914. X of a Kind in a Deck of Cards 一副牌中的X
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- [LeetCode] 47. Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- web版聊天功能简单实现
一.问题 核心点:如何找到要发送的人? 要完成一个功能我觉得首先要分析该功能的逻辑及技术难点,而不是盲目的直接就撸代码,这样非常浪费时间.个人觉得web版聊天功能没什么实际应用场景,以前看过中国移动好 ...
- EPPlus.Core 处理 Excel 报错之天坑 WPS
最近工作中常常有有数据处理的需求,一个Excel动不动就是上十万的数据量,在用 EPPlus.Core 导入数据入库的时候遇到了一个莫名其妙的问题 The given key 'rId2' was n ...
- Leetcode 第137场周赛解题报告
今天的比赛的题目相对来说比较「直白」,不像前几周都是一些特定的算法,如果你没学过不可能想出来. 做了这些周,对leetcode比赛的题目也发现了一些「规律」. 一般前两道题都很「简单」,只要有想法,直 ...