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>;
}
相关推荐
用户004472953825几秒前
练歌镜:让眼镜听懂“循环这一句”
javascript
Penge66611 分钟前
CSS 核心布局指南:盒模型、Flex 布局与 Position 定位
前端
Penge6661 小时前
HTML基础:HTML 标签属性
前端
Penge6661 小时前
HTML 基础:块级元素、行内元素与行内块元素详解
前端
Penge6662 小时前
前端基础:html语义化
前端
用户30816998764852 小时前
同一个端口能被两个程序监听吗?TCP 11 组绑定实测
前端
deli0072 小时前
红绿灯配时实测:固定 60 秒 vs 自适应,2400 辆车差多少
前端
去伪存真2 小时前
井道无信号、满手黑机油,我们如何用 DeepSeek V4 打造不“犯浑”的电梯维保 Agent?
前端·agent
deli0072 小时前
60fps 为什么还是一顿一顿?帧时间曲线实测给你看
前端
时间的情敌3 小时前
Cesium 流动管线、管道动画、管线流向仿真,管网、油气、水利孪生高频需求
前端·交互·cesium