假如你想在VUE的main.js里根据条件按需引入注册组件以及样式,那就这样子写,附赠自己写的vue一个框架配置多系统按需加载系统路由以及组件办法
假如你想在VUE的main.js里根据条件按需引入注册组件以及样式,那就这样子写
举例来说我想要引入大屏的一些组件,但是原来框架已经集成了多个项目,路由也是按需加载的,想要实现组件按需加载
先在main.js旁边新建一个文件web3d.js
import Vue from 'vue';
import dataV from '@jiaminghi/data-view';
Vue.use(dataV);
// 按需引入vue-awesome图标
import Icon from 'vue-awesome/components/Icon';
import 'vue-awesome/icons/chart-bar.js';
import 'vue-awesome/icons/chart-area.js';
import 'vue-awesome/icons/chart-pie.js';
import 'vue-awesome/icons/chart-line.js';
import 'vue-awesome/icons/align-left.js';
// 全局注册图标
Vue.component('icon', Icon);
// 适配flex
import '@/common/flexible.js';
// 引入全局css
import './assets/scss/style.scss';
然后我们打开main.js
import Vue from 'vue';
import { request, post } from './views/co-assets/axios';
import './plugins/utils';
import './plugins/table';
import 'normalize.css/normalize.css'; // A modern alternative to CSS resets
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import locale from 'element-ui/lib/locale/lang/en'; // lang i18n
import '@/styles/index.scss'; // global css
import App from './App';
import store from './store';
import router from './router';
import 'echarts/lib/component/tooltip';
import '@/icons'; // icon
import '@/permission'; // permission control
// 设置如果是大屏系统则引入这些东西,如果不是大屏就不引入
const defaultSettings = require('./settings');
if (defaultSettings.flag === 'cccc') {
require('./web3d.js')
}
// 设置如果是大屏系统则引入这些东西,如果不是大屏就不引入
/**
* If you don't want to use mock-server
* you want to use MockJs for mock api
* you can execute: mockXHR()
*
* Currently MockJs will be used in the production environment,
* please remove it before going online ! ! !
*/
if (process.env.NODE_ENV === 'production') {
const { mockXHR } = require('../mock');
mockXHR();
}
// set ElementUI lang to EN
Vue.use(ElementUI, { locale });
// 如果想要中文版 element-ui,按如下方式声明
// Vue.use(ElementUI)
Vue.config.productionTip = false;
Vue.prototype.$http = request;
Vue.prototype.$post = post;
new Vue({
el: '#app',
router,
store,
render: h => h(App)
});
下面讲的是多系统配置办法,可以不用往下看了哦~~~~
其中的./settings文件是用来配置当前加载哪个系统的,这个是我自己想的多系统使用同一个框架的办法,配合路由使用,大家如果有好的建议可以告诉我哦~~
// const aaaaa = {
// title: 'aaaaa Monitor System',
// titleZH: 'aaaa系統',
// flag: 'aaaaa', // 這個不要改
// logo: 'aaaaa Monitor'
// }
// const system = aaaaa // 當需要使用哪個系統就打開哪個
// const bbbb = {
// title: 'Cable Consumable System',
// titleZH: 'bbbb系統',
// flag: 'bbbb', // 這個不要改
// logo: 'bbbb Monitor'
// }
// const system = bbbb
const cccc = {
title: 'cccc System',
titleZH: 'cccc 系統',
flag: 'cccc', // 這個不要改
logo: 'cccc Monitor'
}
const system = webgl
// const dddd = {
// title: 'HH Matrix System',
// titleZH: 'dddd系統',
// flag: 'dddd', // 這個不要改
// logo: 'dddd'
// }
// const system = dddd
module.exports = {
title: system.title,
titleZH: system.titleZH,
flag: system.flag,
logo: system.logo,
/**
* @type {boolean} true | false
* @description Whether fix the header
*/
fixedHeader: false,
/**
* @type {boolean} true | false
* @description Whether show the logo in sidebar
*/
sidebarLogo: true
}
同时我们可以配置路由文件router/index.js
我把一些无关紧要的删掉了,更清晰看到代码实现过程
import Vue from 'vue';
import Router from 'vue-router';
const defaultSettings = require('../settings');
Vue.use(Router);
/* Layout */
import Layout from '@/layout';
/**
* Note: sub-menu only appear when route children.length >= 1
* Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
*
* hidden: true if set true, item will not show in the sidebar(default is false)
* alwaysShow: true if set true, will always show the root menu
* if not set alwaysShow, when item has more than one children route,
* it will becomes nested mode, otherwise not show the root menu
* redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
* name:'router-name' the name is used by <keep-alive> (must set!!!)
* meta : {
roles: ['admin','editor'] control the page roles (you can set multiple roles)
title: 'title' the name show in sidebar and breadcrumb (recommend set)
icon: 'svg-name' the icon show in the sidebar
breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
}
*/
/**
* constantRoutes
* a base page that does not have permission requirements
* all roles can be accessed
*/
const systemRoutes = {
aaaa: [],
bbbb: [],
cccc: [],
dddd: []
};
export const constantRoutes = systemRoutes[defaultSettings.flag];
const createRouter = () =>
new Router({
// mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
});
const router = createRouter();
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
const newRouter = createRouter();
router.matcher = newRouter.matcher; // reset router
}
export default router;
假如你想在VUE的main.js里根据条件按需引入注册组件以及样式,那就这样子写,附赠自己写的vue一个框架配置多系统按需加载系统路由以及组件办法的更多相关文章
- vue 在main.js里使用vue实例
可以用 Vue.prototype 比如 Vue.prototype.$indicator.close(); 关闭正在加载的动画
- abp vnext2.0之核心组件模块加载系统源码解析与简单应用
abp vnext是abp官方在abp的基础之上构建的微服务架构,说实话,看完核心组件源码的时候,很兴奋,整个框架将组件化的细想运用的很好,真的超级解耦.老版整个框架依赖Castle的问题,vnext ...
- 第三章:模块加载系统(requirejs)
任何一门语言在大规模应用阶段,必然要经历拆分模块的过程.便于维护与团队协作,与java走的最近的dojo率先引入加载器,早期的加载器都是同步的,使用document.write与同步Ajax请求实现. ...
- URL加载系统----iOS工程师必须熟练掌握
URL加载系统----iOS工程师必须熟练掌握 iOS根本离不开网络——不论是从服务端读写数据.向系统分发计算任务,还是从云端加载图片.音频.视频等. 当应用程序面临处理问题的抉择时,通常 ...
- Centos系统创建用户oracle后,用该用户登陆系统,页面加载报错GConf error
Linux 的 GConf error 解决办法 问题: Centos系统创建用户oracle后,用该用户登陆系统,页面加载报错,导致重新进入Centos系统后出现: GConf error:Fail ...
- web 自定义监听器中设置加载系统相关的静态变量及属性
直接上代码: 在src下新建一个StartListener 实现接口ServletContextListener,: /** * @Title:StartListener.java * @Packag ...
- phpcms加载系统类与加载应用类之区别详解
<?php 1. 加载系统类方法load_sys_class($classname, $path = ''", $initialize = 1)系统类文件所在的文件路径:/phpcms ...
- vue项目中主要文件的加载顺序(index.html、App.vue、main.js)
先后顺序: index.html > App.vue的export外的js代码 > main.js > App.vue的export里面的js代码 > Index.vue的ex ...
- C#开发PACS医学影像处理系统(六):加载Dicom影像
对于一款软件的扩展性和维护性来说,上层业务逻辑和UI表现一定要自己开发才有控制权,否则项目上线之后容易被掣肘, 而底层图像处理,我们不需要重复造轮子,这里推荐使用fo-dicom,同样基于Dicom3 ...
- nginx缓存静态资源,只需几个配置提升10倍页面加载速度
nginx缓存静态资源,只需几个配置提升10倍页面加载速度 首先我们看图说话 这是在没有缓存的情况下,这个页面发送了很多静态资源的请求: 1.png 可以看到,静态资源占用了整个页面加载用时的90 ...
随机推荐
- 2.pygame快速入门-绘制图像
介绍 在游戏中能够看到的游戏元素大都是图像 图像文件初始是保存在磁盘上的,如果需要使用,第一步就需要被加载到内存 要在屏幕上看到某一个图像的内容,需要按照三个步骤 使用pygame.image.loa ...
- C#--String.Substring方法
第一种:String.SubString(int start,int length) 截取指定长度的字符串 这里有两个int型的参数 string表示字符串截取的起始位置,length表截取的 ...
- Unity——滚动的小球
Unity--滚动的小球 工程理解 本游戏为通过键盘上的W.A.S.D键控制小球的运动轨迹来对固定位置上的小方块进行碰撞,以此来进行加分计数的. 其中主要对象为小球和自转的小方块:在小球上,我们添加刚 ...
- Python数据分析:实用向
文件处理 导包 import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns ...
- NC-UClient下载安装应用详解
aliases: [] tags : " #NC " summary: [UClient下载安装NCC应用详解] product: [NCX] author : [yaenli] ...
- CPU TLB原理 [转载好文]
首先,我们知道MMU的作用是把虚拟地址转换成物理地址.虚拟地址和物理地址的映射关系存储在页表中,而现在页表又是分级的.64位系统常见的配置是4级页表,就以4级页表为例说明.分别是PGD.PUD.PMD ...
- 第2-4-2章 规则引擎Drools入门案例-业务规则管理系统-组件化-中台
目录 3. Drools入门案例 3.1 业务场景说明 3.2 开发实现 3.3 小结 3.3.1 规则引擎构成 3.3.2 相关概念说明 3.3.3 规则引擎执行过程 3.3.4 KIE介绍 3. ...
- Vue 路由跳转显示空白页面的问题
在写一个登录界面跳转到首页时,路由如下 export default new VueRouter({ routes: [ { path: "/", name: "Logi ...
- virtual继承和不继承
用virtual修饰的虚函数,用来继承重写,没有virtual修饰的,取决于父类 定义 父类 *x=new 子类 首先父类不能调用子类的函数,自能调用本身的函数,所以,只有两种情况,1.无virtua ...
- Navicat mysql创建数据库、用户、授权、连接
一.数据库的创建 调出命令窗口并创建数据库: create database itcast_oa default character set utf8;----创建数据库 二.数案件用户 create ...