reactjs - 如何从文件中导出/导入多个样式组件?
问题描述
我正在使用一个类组件,并希望在其中使用样式化组件。这是我的代码:
styled.js 文件:
import React from 'react';
import styled from "styled-components";
export const sInput = styled.input`
margin:1% 0;
padding: 1%;
border: 1px solid black;
background: #323232;
color: ivory;
`;
export const sButton = styled.button`
background: coral;
margin: 0 .5%;
padding: 1%;
border: none;
`;
Search.js 文件:
import React from 'react';
import {sInput, sButton} from "./styled";
class Search extends React.Component{
constructor(){
super();
this.state = {
search: ""
}
}
handleChange = e =>{
this.setState({
search: e.target.value
})
console.log(this.state.search)
}
handleSubmit = e =>{
e.preventDefault();
console.log("search",this.state.search)
this.props.search(this.state.search)
this.setState({
search:""
})
}
render(){
return(
<div className="search">
<form>
<label htmlFor="search"></label>
<sInput
type="text"
name="search"
value = {this.state.search}
placeholder="search your list.."
onChange = {this.handleChange}/>
<sButton type="submit" onClick ={this.handleSubmit}>Search</sButton>
<sButton type="submit" onClick = {this.props.clearSearch} >Clear Search</sButton>
</form>
</div>
);
}
}
export default Search;
在 VS 代码中导入 {sInput, sButton} from "./styled"; 显示为灰色,并表示文件中的任何位置都没有读取它。我不知道如何解决这个问题,因为我的文件结构是正确的。我猜我错误地导出/导入它们?
编辑:没有正确标记样式组件,它们需要大写。sInput=>SInput
解决方案
推荐阅读
- java - 如何使用 SAP Cloud SDK 3.2.0 在 Java 中检索目标?
- swift - Swift5 文本字段的几种输入法(PickerView & System字母键盘)同时进行
- javascript - AWS Amplify 错误从 aws-amplify 导入 StorageProvider 类
- sql - 如何有效地对复杂 SQL 查询的结果进行分页?
- c# - 我如何连接电子邮件地址?C#
- java - 在应用程序类中使用静态接口是否安全?
- c++ - 通过槽和信号在不同线程中的两个qt对象之间进行通信
- azure - 想要从 Microsoft Office 365 管理 API 获取用户
- angular - 在 ng build prod 之后我无法使用我的 rest api
- java - 保存到流管道中的数据库