【问题标题】:is there any way to import file from another parent folder css react js有什么方法可以从另一个父文件夹 css react js 导入文件
【发布时间】:2021-03-11 06:57:55
【问题描述】:

这是我的文件,在组件文件夹中的 Sidebar.js 中,我需要从样式文件夹中导入 sidebar.css,组件和样式在父文件夹侧边栏中。

请给我一个解决方案

【问题讨论】:

  • 你想将 sidebar.css 导入到哪里?
  • 得到了答案兄弟,将css文件导入sidebar.js

标签: css reactjs import directory filesystems


【解决方案1】:

看来,您正在寻找这个:import "../styles/sidebar.css"

【讨论】:

    【解决方案2】:

    试试这个方法

    sidebar.css

    import { StyleSheet, Platform } from "react-native";
    
    export const sidebar = StyleSheet.create({});
    

    Sidebar.js

    import { sidebar } from "../styles/sidebar";
    
    class Sidebar extends React.Component {
      clickMe() {
        alert("Hi!");
      }
      render() {
        return (
          <div className="box" onClick={this.clickMe.bind(this)}>
            Hello {this.props.name}. Please click me.
          </div>
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 2023-01-25
      • 2018-10-10
      • 1970-01-01
      • 2015-11-11
      相关资源
      最近更新 更多