位置: 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(乐吾实验学校网站)

  • 个人所得税如何办理退税
  • 公司的股东就是公司的发起人
  • 融资租赁税率是什么意思
  • 息税前利润变动率
  • 小规模纳税人企业所得税怎么计算
  • 利润表的调整
  • 企业所得税免税项目
  • 不动产什么时候可以抵扣进项税额
  • 加计抵扣进项税额会计分录
  • 什么情况下可要求厂商出品质保证书
  • 商业企业收取各项费用的税务与会计处理
  • 计提企业所得税怎么计算
  • 托收承付是收到钱了吗
  • 外资企业所得税优惠政策
  • 纳税申报有哪些规定
  • 企业重组的所得税怎么算
  • 公司注销时资本公积为股东出资款要缴税吗?
  • 电脑开机无启动
  • 三栏式明细账目录填写范本
  • 母公司对子公司减资
  • win8电脑系统还原
  • 营改增建筑业税率是多少
  • Win10无法访问局域网计算机
  • encodetext
  • 子公司之间能否相互承包工程
  • conda不是内部或外部命令
  • vite配置详解
  • php中strcmp函数
  • elipse左侧菜单栏显示
  • 深度学习中的注意力机制模型及代码实现(SE Attention、CBAM Attention)
  • 出口发票的开具时间问题
  • 如何修改python
  • 长期应付款列报为什么是后一年的
  • 资产负债表中应收账款的计算公式
  • 工会经费按应发还是实发缴纳
  • 小微企业所得税优惠政策最新2023
  • 保证金存款账户需要销户吗
  • 成本核算方法是指
  • 普通发票上的银行账户有规定吗
  • 小微企业免征的增值税怎么做账
  • 车辆维修费如何赔偿
  • 事业单位无形资产包括
  • 进项税额是意思
  • 补计提去年所得税会影响当月资产
  • 已认证的红字发票怎么开
  • 中小企业收款
  • 以前年度损益调整是什么意思
  • 预收账款常见的问题
  • 营改增政策汇总
  • 增值税发票超过多久不能抵扣
  • 公司购入的房子卖了,如何交增值税
  • 当期不得免征和抵扣税额
  • 即征即退的增值税退城建税吗
  • window10打开rar文件
  • ubuntu 20.04拨号上网
  • ubuntu如何清理垃圾
  • mac的分辨率怎么调
  • win7搜索选项
  • win8系统出现闪屏
  • win7桌面壁纸自动更换关闭
  • perl 批量注释
  • linux安装ko驱动
  • meta 标签
  • jquery插件怎么写
  • 深入浅出python
  • jquery创建表单
  • activity的作用和生命周期
  • unity的invoke
  • ASP小贴士/ASP Tips javascript tips可以当桌面
  • javascript教程doc
  • java 信号量 超时
  • python多线程怎么用
  • 怎样下载金税盘
  • 江苏电子税务局官网登录入口
  • 出口发票与报关单名称不一致影响退税吗
  • 苏州昆山税务局电话号码
  • 精准扶贫有哪些分类措施
  • 广州税务举报电话
  • 差旅费的补助计入哪个费用
  • 政府发放奖金给企业怎么入账
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设