位置: IT常识 - 正文

微前端-qiankun(微前端Qiankun 子应用css后加载问题)

编辑:rootadmin
微前端-qiankun 概念使用框架:qiankun介绍:

推荐整理分享微前端-qiankun(微前端Qiankun 子应用css后加载问题),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:微前端Qiankun优缺点,微前端Qiankun 子应用css后加载导致页面闪动,微前端qiankun子应用通信,微前端qiankun子应用通信,微前端Qiankun介绍,微前端Qiankun 子应用css后加载导致页面闪动,微前端Qiankun 子应用css后加载导致页面闪动,微前端Qiankun,内容如对您有帮助,希望把文章链接给更多的朋友!

qiankun 是一个基于 single-spa 的微前端实现库,旨在帮助大家能更简单、无痛的构建一个生产可用微前端架构系统。 qiankun官网:Go 当使用 iframe 整合系统时,假设我们有系统 A, 当我们想把系统 B 引入 A 系统时,只需要 B 系统提供一个 url 给 A 系统引用即可,这里我们把 A 系统叫做父应用,把 B 系统叫做子应用。同样的,微前端也延续了这个概念,微前端在使用起来基本和使用 iframe 一样平滑。

结构:

分为:主应用(父),微应用(子) 图1:

使用案例:目标:

点击one按钮,切换到one微应用 点击two按钮,切换到two微应用 并且每个微应用都可以跳转自己的路由

步骤:

创建主应用项目创建微应用项目将微应用挂到主应用项目中1. 在主应用中安装qiankun框架$ yarn add qiankun # 或者 npm i qiankun -S2. 在 主应用 中注册微应用

main.js:

import { createApp } from 'vue'import App from './App.vue'import router from './router/index'import ElementPlus from 'element-plus'import 'element-plus/dist/index.css'import { registerMicroApps, start } from 'qiankun';registerMicroApps([ { name: "vueChildOne", props: { age: 10 }, //给子应用传数据 entry: "//localhost:3001", //默认会加载这个html,解析里面的js,动态执行(子应用必须支持跨域)里面,是用fetch去请求的数据 container: "#child-one-content", //挂载到主应用的哪个元素下 activeRule: "/child-one", //当我劫持到路由地址为//child-one时,我就把http://localhost:3001这个应用挂载到#child-one-content的元素下 }, { name: 'vueChildTwo', entry: '//localhost:3002', // entry: { scripts: ['//http://192.168.2.120:3001/main.js'] }, container: '#child-two-content', activeRule: '/child-two', },]);// start(); // 启动qiankun,这里不在一开始的时候使用createApp(App).use(ElementPlus).use(router).mount('#app-base')

App.vue

<template> <div> <div class="bens"> <el-button type="primary" @click="$router.push('/child-one')">childOne</el-button> <el-button type="primary" @click="$router.push('/child-two')">childTwo</el-button> </div> <router-view></router-view> </div></template><script>export default { name: "App", components: {},};</script><style>.bens { width: 100%; display: flex; justify-content: center; position: absolute; top: 15px; left: 0; z-index: 9999999;}#app-base { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px;}</style>微前端-qiankun(微前端Qiankun 子应用css后加载问题)

index.html:

// 将id:app 改为 app-base 自定义就行,只要与main.js对应起来,切不与微应用重复<div id="app-base"></div>

router.js

import { createRouter, createWebHistory } from "vue-router";// 2. 配置路由const routes = [ { path: '/child-one', component: () => import('@/views/childOne/index.vue'), }, { path: '/child-two', component: () => import('@/views/childTwo/index.vue'), },];// 1.返回一个 router 实列,为函数,里面有配置项(对象) historyconst router = createRouter({ history: createWebHistory(), routes,});// 3导出路由 然后去 main.ts 注册 router.tsexport default router

childOne/index.vue

<template> <h2>我是 主应用 one</h2> <div id="child-one-content"></div></template><script>import { start } from "qiankun";export default { name: "childOne", components: {}, mounted() { // 启动微应用 if (!window.qiankunStarted) { window.qiankunStarted = true; start(); } },};</script><style></style>

childTwo/index.vue

<template> <h2>我是 主应用 two</h2> <div id="child-two-content"></div></template><script>import { start } from "qiankun";export default { name: "childTwo", components: {}, mounted() { // 启动微应用 if (!window.qiankunStarted) { window.qiankunStarted = true; start(); } },};</script><style></style>4. 微应用配置child-one

src下创建public-path.js

if (window.__POWERED_BY_QIANKUN__) { __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__}

main.js

import { createApp } from 'vue'import App from './App.vue'import router from './router/index'import './public-path' // 引入public-path.js// createApp(App).mount('#app')let instance = null;function render(props = {}) { if (instance) return; const { container } = props; console.log(container); instance = createApp(App) .use(router) .mount(container ? container.querySelector("#app-child-one") : "#app-child-one");}// 独立运行时if (!window.__POWERED_BY_QIANKUN__) { render();}export async function bootstrap() { console.log("[vue] vue app bootstraped");}export async function mount(props) { console.log("[vue] props from main framework", props); render(props);}export async function unmount() { //可选链操作符 instance.$destroy?.(); instance = null;}

index.html

<!DOCTYPE html><html lang=""> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <link rel="icon" href="<%= BASE_URL %>favicon.ico"> <title><%= htmlWebpackPlugin.options.title %></title> </head> <body> <noscript> <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> </noscript> <div id="app-child-one"></div> <!-- built files will be auto injected --> </body></html>

vue.config.js

module.exports = { lintOnSave: false, devServer: { port: "3001", headers: { "Access-Control-Allow-Origin": "*", //所有人都可以访问我的服务器 }, }, configureWebpack: { output: { // library: `${name}-[name]`, library: `vueChildOne`, libraryTarget: "umd", // 把微应用打包成 umd 库格式 // jsonpFunction: `webpackJsonp_${name}`, }, },};

router.js

import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";// 2. 配置路由const routes = [ { path: '/', component: () => import('@/views/home/index.vue'), }, { path: '/about', component: () => import('@/views/about/index.vue'), },];// 1.返回一个 router 实列,为函数,里面有配置项(对象) historyconst router = createRouter({ history: createWebHashHistory('/child-one'), routes,});// 3导出路由 然后去 main.ts 注册 router.tsexport default router5. 微应用配置child-two

与child-two同理,只要把对应的" child-one " 换成" child-two "即可

demo代码地址

码云地址

本文链接地址:https://www.jiuchutong.com/zhishi/292318.html 转载请保留说明!

上一篇:在葡萄牙海岸游泳的抹香鲸妈妈和患白化病的抹香鲸宝宝 (© Flip Nicklin/Minden Pictures)(葡萄牙海岸风光)

下一篇:基于乐吾乐核心库开发的组态编辑器-前端vue2+element,后端node+koa2+mysql5.7(乐吾实验学校网站)

  • iqoo8有hifi芯片吗(iqoo8支持lhdc吗)

    iqoo8有hifi芯片吗(iqoo8支持lhdc吗)

  • 雷蛇鼠标怎么调dpi(雷蛇鼠标怎么调灯光颜色)

    雷蛇鼠标怎么调dpi(雷蛇鼠标怎么调灯光颜色)

  • switch pro手柄怎么关机(switchpro手柄怎么连接ns)

    switch pro手柄怎么关机(switchpro手柄怎么连接ns)

  • 为什么通过手机号搜不到对方微信(为什么通过手机号码添加微信找不到人)

    为什么通过手机号搜不到对方微信(为什么通过手机号码添加微信找不到人)

  • 微信把对方删除之后聊天记录还在吗(微信把对方删除了对方知道吗)

    微信把对方删除之后聊天记录还在吗(微信把对方删除了对方知道吗)

  • 双十一多久没发货可以补偿(双十一好几天不发货)

    双十一多久没发货可以补偿(双十一好几天不发货)

  • 爱奇艺如何发彩色弹幕(爱奇艺如何发彩铃视频)

    爱奇艺如何发彩色弹幕(爱奇艺如何发彩铃视频)

  • 不属于计算机病毒特征的是(不属于计算机病毒特性的事什么)

    不属于计算机病毒特征的是(不属于计算机病毒特性的事什么)

  • 闲鱼支持花呗吗(闲鱼支持花呗吗是真的吗)

    闲鱼支持花呗吗(闲鱼支持花呗吗是真的吗)

  • 固态一定要4k对齐吗(固态硬盘必须要4k对齐吗)

    固态一定要4k对齐吗(固态硬盘必须要4k对齐吗)

  • 华为无线耳机怎么关机(华为无线耳机怎么开机)

    华为无线耳机怎么关机(华为无线耳机怎么开机)

  • 微信解锁密码忘记了怎么解除(微信解锁密码忘记了打不开怎么办)

    微信解锁密码忘记了怎么解除(微信解锁密码忘记了打不开怎么办)

  • qq三个月亮是多少级(qq三个月亮是多少天)

    qq三个月亮是多少级(qq三个月亮是多少天)

  • 手机qq怎么推荐好友(手机qq怎么推荐给好友)

    手机qq怎么推荐好友(手机qq怎么推荐给好友)

  • OPPO k5支持息屏按键拍照吗(oppok5锁屏后显示时间怎么设置)

    OPPO k5支持息屏按键拍照吗(oppok5锁屏后显示时间怎么设置)

  • 怎么增加手机内存(更换手机后如何删除旧手机上内容)

    怎么增加手机内存(更换手机后如何删除旧手机上内容)

  • 小米9se支持nfc吗(小米9se支持nfc功能吗能刷公交吗)

    小米9se支持nfc吗(小米9se支持nfc功能吗能刷公交吗)

  • 人工智能的应用(人工智能的应用论文)

    人工智能的应用(人工智能的应用论文)

  • win10改密码在哪(win10如何更改密码)

    win10改密码在哪(win10如何更改密码)

  • VMware8虚拟机的BIOS有哪些地方是可以优化(虚拟机系统vmware)

    VMware8虚拟机的BIOS有哪些地方是可以优化(虚拟机系统vmware)

  • 无线路由器如何安装 无线路由器安装方法图文介绍(无线路由器如何桥接wifi信号)

    无线路由器如何安装 无线路由器安装方法图文介绍(无线路由器如何桥接wifi信号)

  • Win7安装高版本的NodeJS方法,亲测可用(win7安装高版本chrome)

    Win7安装高版本的NodeJS方法,亲测可用(win7安装高版本chrome)

  • 半年奖个人所得税怎么算的
  • 外管证是在当地办理还是在外地办理
  • 新个税年终奖计算公式
  • 坏账损失计入什么
  • 个人所得税B表和C表
  • 待认证进项税期末余额在贷方
  • 佣金开什么发票内容
  • 纳税申报表真伪验证
  • 合伙制创投企业
  • 企业如何加强应收账款的管理
  • 零税率的发票
  • 未开票收入如何申报增值税,下个月怎么操作
  • 融资租赁的服务费的标准
  • 保安公司开具的发票
  • 虚开发票可以做进项税额转出分录吗?
  • 异地预缴增值税后本地还要交吗
  • 普通发票离线限额为0
  • 印花税计入股票成本吗
  • 流转税税额
  • 公司减少注册资本的程序
  • 工资条上税基调整是啥意思
  • etc充值发票可以抵扣税吗
  • 进厂的政府补贴怎么拿
  • 情绪情感的特点
  • 单位性质有哪些类型
  • 债务重组是什么工作
  • dgservice.exe是什么软件
  • 蓝山公馆的房子怎么样
  • 应交税费会计分录例题
  • 完美解决显卡利用率低
  • vue中watch监听对象的变化
  • 聊聊vue3的defineProps、defineEmits、defineExpose
  • jqueryfor
  • ChatGPT的了解与初体验
  • JS初识
  • 出口海运费222011
  • 新企业会计准则
  • 财务中常有提到的问题
  • pd python
  • html前端技术
  • php变量名称中可以包含哪些元素
  • 安装路灯会计分录
  • 建筑业综合税率13.8%
  • 境外汇款收款人承担手续费
  • 计提减值准备是利空吗
  • 账实核对是指各种财产物资与债权债务的账面余额
  • 红冲作废怎么处理
  • 产品研发项目管理 系统 国外
  • 如何确认产品销售收入
  • 固定资产折旧提头不提尾
  • 成本法核算的投资收益缴纳企业所得税
  • 实际验收入库是什么科目
  • 物料损耗率计算例题及答案
  • 外聘人员个人简历
  • 投资收益的账务怎么处理
  • 未开票收入下月开票会计分录
  • 没有发票只有收据可以入账吗
  • 本期应补退税额是什么意思
  • 跨行收报属于什么科目
  • 电子承兑汇票如何入账
  • 32.exe 什么病毒
  • win8系统怎么取消屏保
  • windows 查看补丁
  • winxp破解登录密码
  • win8.1语言设置
  • win8分屏快捷键
  • win8系统教程
  • win10系统预览版
  • win10下itunes
  • win10 rs3
  • [置顶]电影名字《收件人不详》
  • linux判断脚本执行成功
  • shell 循环 for
  • css选择器教程
  • vue.js computed
  • 安卓调用系统相机
  • 税务机关落实六保六稳
  • 没有核定印花税罚款吗
  • 企业所得税纳税申报表A类
  • 收到税务局发的多条宣传短信
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设