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 ...
随机推荐
- 201871010112-梁丽珍《面向对象程序设计(java)》第十四周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- 201871010105-曹玉中《面向对象程序设计(java)》第七周学习总结
201871010105-曹玉中<面向对象程序设计(java)>第七周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这 ...
- 软件工程1916|W(福州大学)_助教博客】团队第六次作业(第9次)成绩公示
1. 作业链接: 团队作业第六次-团队Github实战训练 2. 评分准则: 本次作业评分分为两部分,一部分是博客分数(满分100分),另一部分是工程能力分数(满分30分). 博客分数计算方式: 团队 ...
- docker 中,修改了 mysql 配置,如何重启 mysql?
直接重新启动容器: docker restart containerID/containerName
- Linux环境下sudo切换用户后执行其他命令
https://blog.csdn.net/liangxw1/article/details/80106465
- 莫烦TensorFlow_10 过拟合
import tensorflow as tf from sklearn.datasets import load_digits from sklearn.cross_validation impor ...
- 【目标检测】SSD:
slides 讲得是相当清楚了: http://www.cs.unc.edu/~wliu/papers/ssd_eccv2016_slide.pdf 配合中文翻译来看: https://www.cnb ...
- async和await的用法
function fn(){ return "aa"; } console.log(fn())// 如果直接写个函数return一个值,那么打印的肯定就是aa async func ...
- 数据库的查——select的基本使用
--创建学生表 create table students ( id int unsigned not null auto_increment primary key, name varchar(20 ...
- [LeetCode] 674. Longest Continuous Increasing Subsequence 最长连续递增序列
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...