首页 > 其他分享 >管理端根据角色,获取动态路由,动态引用页面的时候,Vue2和vue3的使用方法

管理端根据角色,获取动态路由,动态引用页面的时候,Vue2和vue3的使用方法

时间:2024-03-04 16:35:32浏览次数:22  
标签:views itemChild fileModule item Vue2 vue3 path 动态 true

1、vue2 使用的方法,重点注意引用组件的时候使用的require
let temp=[];
children.map((itemChild)=>{
let visible=(itemChild.menuType=='F')?true:false;
temp.push({
path: itemChild.path,
component:resolve => require([@/views/${itemChild.component}], resolve),
meta: { title: itemChild.menuName,parentMenuName:item.menuName, affix: true },
hidden:visible
})
})
routes.push({
path: item.path,
component: Layout,
redirect: children[0].path,
alwaysShow: true, // will always show the root menu
meta:{
title:item.menuName,
icon: item.icon
},
children: temp
})
2、vue3使用的方法 注意loadFile方法
async function loadFile(item: any) {
// if (item.type === 4) return import('@/views/iframe.vue')
let fileModule = await import('@/views' + item.url)
.catch((err) => {
// console.error(err);
return false
})
if (!fileModule) {
fileModule = import('@/views/develop.vue')
console.error('文件不存在或者文件加载出现错误');
}
return fileModule
}
var route = {
name: item.name,
path: item.url,
component: () => loadFile(item),
meta: {
id: item.id,
url: item.url,
title: item.name,
requiresAuth: true,
rootMenu: item.rootMenu,
keepAlive: true
},
}
routes.push(route)

标签:views,itemChild,fileModule,item,Vue2,vue3,path,动态,true
From: https://www.cnblogs.com/menglm/p/18052067

相关文章

  • springboot3+vue3(三)接口参数校验Spring Validation框架
    1、引入Validation依赖<!--参数校验依赖validation--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId></dependency>va......
  • 动态分配内存new和delete
    #include<iostream>/*动态分配内存用new关键字,语法:new变量类型(初始值)C++11支持{}newint(5)----申请了一个整型内存,并赋初值为5但是由于动态分配的内存没有变量名,需要用一个指针接着它,操作指针来使用。成功会返回一个地址,不成功返回空地址。......
  • day54 动态规划part11 代码随想录算法训练营 123. 买卖股票的最佳时机 III
    题目:123.买卖股票的最佳时机III我的感悟:困难像弹簧,你强他就弱,你弱它就强!理解难点:5个状态,听课笔记:我的代码:classSolution:defmaxProfit(self,prices:List[int])->int:iflen(prices)==1:return0#5种状态#dp[i......
  • springboot3+vue3(二)注册接口
     为了方便实体类操作,这里添加一下lombok的依赖,添加好以后右键重新加载mavenlombok注解含义大全:https://www.jianshu.com/p/41c4a226e955<!--lombok依赖--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifa......
  • vue3中使用@vue-office/pdf项目中报Cannot set properties of undefined (setting 'wi
    最近项目研发的时候需要使用到pdf预览的功能,规定需要使用@vue-office/pdf插件0.2.5版本号,在使用的时候,一直无法正常运行,错误如下 但是在其他项目中却可以正常使用,想来应该是项目中的某个插件和这个有影响(不兼容)导致pdf无法预览,最终确定是vue版本的问题。正常使用的版本应该为......
  • vue2响应式原理
    Vue.js是一个流行的JavaScript前端框架,它的核心特性之一就是响应式数据绑定。Vue.js2.x版本的响应式原理主要基于Object.defineProperty函数来实现。Vue.js的响应式原理大致可以描述为以下几个步骤:数据劫持:当Vue实例创建时,Vue会遍历data选项中的属性,并使用Obje......
  • uniapp开发微信小程序,动态排列组件的解决方案。
    微信小程序开发里面,并不支持<component:is="item",虽然微信小程序提供了WXML提供模板(template),对于uniapp并不管用,编译后,所以解决方案,只有目前(截止2022-04-15)只有两个:1.使用v-if,遍历组件,判断位置,来显示组件,达到排列要求2.第二种没那么麻烦,比较神奇,使用flex布局的order属性,外层......
  • ElementPlus+Vue3使用cdn方式编写页面及引入图标
    完整代码1<!DOCTYPEhtml>2<htmllang="en">34<head>5<metacharset="UTF-8">6<metaname="viewport"content="width=1000,initial-scale=1.0">7<title>模型管理&......
  • FRPC动态启动
    需求目前FRP客户端默认是带配置文件启动,有部分需求是按需动态启动,所以可由应用程序动态管理和启停。以TCP为例查看参数frpctcp-h`RunfrpcwithasingletcpproxyUsage:frpctcp[flags]Flags:--bandwidth_limitstringbandwidthlimit--bandwidth_limit_mo......
  • springboot3+vue3大事件(一)项目准备工作
     1、执行sql脚本,准备数据库表--创建数据库createdatabasedev;--使用数据库usedev;--用户表createtableuser(idintunsignedprimarykeyauto_incrementcomment'ID',usernamevarchar(20)notnullunique......