qiankun实现基座、子应用样式隔离

目录

qiankun 实现主应用与子应用样式隔离

  • qiankun 之中默认的样式隔离是针对子应用与子应用之间的。至于主应用的样式会影响到子应用,若需要,则需要配置进行隔离
  • 解决方法:
    1:每个应用的样式使用固定的格式 eg:react 项目=> react-memu 不推荐
    2: 通过 css-modules 的方式给每个应用自动加上前缀
    3: 使用CSS-in-JS来实现样式隔离 ( 推荐 )

使用CSS-in-JS来实现样式隔离

  • 使用react-jss 或者 styled-components都可以实现样式隔离

react-jss

  • cnpm i react-jss
js 复制代码
import React from 'react';
import { createUseStyles } from 'react-jss';

const useStyles = createUseStyles({
  myButton: {
    color: 'green',
    margin: {
      top: 5,
      right: 0,
      bottom: 5,
      left: 0,
    },
    '& span': {
      fontWeight: 'bold',
    },
  },
});

function MyComponent() {
  const classes = useStyles();
  return <button className={classes.myButton}>Submit<span>Button</span></button>;
}

styled-components

  • cnpm i styled-components
js 复制代码
import React from 'react';
import styled from 'styled-components';

const Container = styled.div`
  .div {
    color: red
  }
`;

function MyComponent() {
  return <Container>
    My Component
    <div className="div">color</div>
  </Container>;
}
相关推荐
cg339 小时前
开源项目自动化:用 GitHub Actions 让每个 Issue 都被温柔以待
前端
haierccc9 小时前
Win7、2008R2、Win10、Win11使用FLASH的方法
前端·javascript·html
We་ct9 小时前
LeetCode 50. Pow(x, n):从暴力法到快速幂的优化之路
开发语言·前端·javascript·算法·leetcode·typescript·
柠檬味的Cat9 小时前
使用腾讯云COS作为WordPress图床的实践
前端·github·腾讯云
Hilaku9 小时前
卷AI、卷算法、2026 年的前端工程师到底在卷什么?
前端·javascript·面试
非凡ghost9 小时前
AIMP(音乐播放软件)
前端·windows·音视频·firefox
xiaotao1319 小时前
Vite 完全学习指南
前端·vite·前端打包
弓.长.9 小时前
ReactNative for OpenHarmony项目鸿蒙化三方库:react-native-svg(CAPI) — 矢量图形组件
react native·react.js·harmonyos
军军君019 小时前
Three.js基础功能学习十五:智能黑板实现实例二
开发语言·前端·javascript·vue.js·3d·threejs·三维
IT枫斗者9 小时前
构建具有执行功能的 AI Agent:基于工作记忆的任务规划与元认知监控架构
android·前端·vue.js·spring boot·后端·架构