假如你想在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一个框架配置多系统按需加载系统路由以及组件办法的更多相关文章

  1. vue 在main.js里使用vue实例

    可以用 Vue.prototype 比如 Vue.prototype.$indicator.close(); 关闭正在加载的动画

  2. abp vnext2.0之核心组件模块加载系统源码解析与简单应用

    abp vnext是abp官方在abp的基础之上构建的微服务架构,说实话,看完核心组件源码的时候,很兴奋,整个框架将组件化的细想运用的很好,真的超级解耦.老版整个框架依赖Castle的问题,vnext ...

  3. 第三章:模块加载系统(requirejs)

    任何一门语言在大规模应用阶段,必然要经历拆分模块的过程.便于维护与团队协作,与java走的最近的dojo率先引入加载器,早期的加载器都是同步的,使用document.write与同步Ajax请求实现. ...

  4. URL加载系统----iOS工程师必须熟练掌握

    URL加载系统----iOS工程师必须熟练掌握     iOS根本离不开网络——不论是从服务端读写数据.向系统分发计算任务,还是从云端加载图片.音频.视频等.   当应用程序面临处理问题的抉择时,通常 ...

  5. Centos系统创建用户oracle后,用该用户登陆系统,页面加载报错GConf error

    Linux 的 GConf error 解决办法 问题: Centos系统创建用户oracle后,用该用户登陆系统,页面加载报错,导致重新进入Centos系统后出现: GConf error:Fail ...

  6. web 自定义监听器中设置加载系统相关的静态变量及属性

    直接上代码: 在src下新建一个StartListener 实现接口ServletContextListener,: /** * @Title:StartListener.java * @Packag ...

  7. phpcms加载系统类与加载应用类之区别详解

    <?php 1. 加载系统类方法load_sys_class($classname, $path = ''", $initialize = 1)系统类文件所在的文件路径:/phpcms ...

  8. vue项目中主要文件的加载顺序(index.html、App.vue、main.js)

    先后顺序: index.html > App.vue的export外的js代码 > main.js > App.vue的export里面的js代码 > Index.vue的ex ...

  9. C#开发PACS医学影像处理系统(六):加载Dicom影像

    对于一款软件的扩展性和维护性来说,上层业务逻辑和UI表现一定要自己开发才有控制权,否则项目上线之后容易被掣肘, 而底层图像处理,我们不需要重复造轮子,这里推荐使用fo-dicom,同样基于Dicom3 ...

  10. nginx缓存静态资源,只需几个配置提升10倍页面加载速度

    nginx缓存静态资源,只需几个配置提升10倍页面加载速度 首先我们看图说话 这是在没有缓存的情况下,这个页面发送了很多静态资源的请求:   1.png 可以看到,静态资源占用了整个页面加载用时的90 ...

随机推荐

  1. 京东云开发者|京东云RDS数据迁移常见场景攻略

    云时代已经来临,云上很多场景下都需要数据的迁移.备份和流转,各大云厂商也大都提供了自己的迁移工具.本文主要介绍京东云数据库为解决用户数据迁移的常见场景所提供的解决方案. 场景一:数据迁移上云 数据迁移 ...

  2. ubuntu+Django + nginx + uwsgi 部署

    ubuntu+Django + nginx + uwsgi 部署 0.前期准备 注意:以下几件事都必须在激活虚拟环境下完成 运行以下命令生成项目所需的依赖列表,会在项目根目录生成一个requireme ...

  3. 「Python实用秘技11」在Python中利用ItsDangerous快捷实现数据加密

    本文完整示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/PythonPracticalSkills 这是我的系列文章「Python实用秘技」的第11 ...

  4. 【网络】安装Nginx笔记

    目录 前言 安装前先更新下 安装依赖库 下载Nginx Nginx编译配置 编译&安装&验证nginx Nginx服务配置 配置SSL 参考 前言 up安装nginx主要是为了在服务器 ...

  5. ROS应用层通信协议解析

    参考:http://wiki.ros.org/ROS/Master_API http://wiki.ros.org/ROS/Connection Header 说明 ROS本质上就是一个松耦合的通信框 ...

  6. npm安装hexo报错

    报错提示 npm WARN saveError ENOENT: no such file or directory, open '/home/linux1/package.json' npm noti ...

  7. ADPCM(自适应差分脉冲编码调制)的原理和计算

    关于ADPCM ADPCM(Adaptive Differential Pulse Code Modulation, 自适应差分脉冲编码调制) 是一种音频信号数字化编码技术, 音频压缩标准G.722, ...

  8. 基于.net C# Socket WinForm MQTT 客户端开发

    1.什么是MQTT? MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议),是一种基于发布/订阅(publish/subscribe)模式的&quo ...

  9. 论文解读(CDCL)《Cross-domain Contrastive Learning for Unsupervised Domain Adaptation》

    论文信息 论文标题:Cross-domain Contrastive Learning for Unsupervised Domain Adaptation论文作者:Rui Wang, Zuxuan ...

  10. HashMap为何线程不安全?HashMap,HashTable,ConcurrentHashMap对比

    这两天写爬虫帮组里收集网上数据做训练,需要进一步对收集到的json数据做数据清洗,结果就用到了多线程下的哈希表数据结构,猛地回想起自己看<Java并发编程的艺术>框架篇的时候,在Concu ...