css - 如何将颜色从 colors.jsx 导入到另一个文件
问题描述
我有一个 src/config/colors.jsx 文件,其中包含以下代码:
const colors = {
pink: '#f1316b',
}
export default colors;
我还有另一个 Button.jsx 文件如下
import styled from 'styled-components';
const Button = styled.button`
width: 100px;
height: 48px;
border-radius: 24px;
background-color: #f1316b;
color: #fff;
border: 0;
`;
export default Button;
如何从颜色中导入粉红色以用作按钮中的背景颜色?
解决方案
不完全确定您的文件夹结构,但在 Button 组件内部(假设它也在src
文件夹中),只需执行
import styled from 'styled-components';
import colors from './config/colors.jsx';
const Button = styled.button`
width: 100px;
height: 48px;
border-radius: 24px;
background-color: colors.pink;
color: #fff;
border: 0;
`;
export default Button;
你也可以添加你想要的其他颜色
推荐阅读
- python - 需要 Kivy 文本过滤说明
- laravel - 创建或删除或更新模型时,Laravel Scout Elasticsearch Driver 不会更新搜索索引
- java - 在equals方法中比较两个对象名称
- c - gcc - 致命错误:libusb.h:没有这样的文件或目录
- node.js - 为 Nodejs 应用程序登录后难以显示用户名
- excel - 是否可以在另一个地方镜像图表?
- javascript - 在 axios.get reactJS 上请求中止
- java - Xposed findClass() 返回 java.lang.Class
- c# - 何时以及如何使用构造函数初始化(视图)模型,目的是正确设置对象的所有道具并且忘记任何道具
- python - 主窗口前的 PyQt5 启动画面