css - SASS React.js 未定义变量
问题描述
我是 SASS 和 React.js 的新手。我在这个平台上搜索了很多答案,似乎无法发现我的问题。我有一个部分文件_variables.scss
,如下所示:
// Fonts
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@200;300;400;500;600;700&display=swap');
$raleway-font: 'Raleway', sans-serif;
我已将其与其他文件App.scss
一起导入到我的中,例如:scss
// Utilities
@import 'styles/variables';
// Stylesheets
@import '~bootstrap/scss/bootstrap';
@import 'components/navigationBar/navbar';
@import 'components/main/main';
@import 'components/main/mostRecent/mostRecent';
@import 'components/main/mostRecent/recentCard/recentCard';
@import 'components/main/featuredCard/featuredCard';
但是,当我尝试在任何文件中使用该变量时,例如featuredCard.scss
- 我得到了错误:
SassError: Undefined variable: "$raleway-font".
请注意,我使用了 create-react-app,并安装了"node-sass": "^4.14.1"
. 我正在将我的文件导入到jsx
带有import './featuredCard.scss';
.
有谁知道为什么会这样?
解决方案
显然您错误地导入了变量的地址,
@import 'styles/variables';
一种检查您是否没有正确放置 的地址的方法variables.scss
是将代码复制到'components / main / featuredCard / featuredCard';
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@200;300;400;500;600;700&display=swap');
$raleway-font: 'Raleway', sans-serif;
//code featuredCard
并发表评论 @import 'styles/variables';
推荐阅读
- javascript - 如何在javascript中循环一个函数
- javascript - getElementsByFieldName ?获取具有特定字段名称的无线电枚举的所有元素
- datepicker - Vuetify datepicker year only max date doesn't trigger vuex state mutation
- python - 在python中将文本文件解析为数据框
- sql - 来自 2 个不同数据源(同一服务器)的联合
- android - 屏幕锁定时从后台启动活动
- python - 根据请求验证(Django Rest 框架)序列化器字段
- git - 签出单个文件以保留历史记录
- python - 用于图像处理的 cython 嵌套循环
- oracle - 在应用程序设计器“指定的列名数量无效”上构建视图时出错