gpt4 book ai didi

javascript - 样式化的 Prop 颜色,无法更改电影名称

转载 作者:行者123 更新时间:2023-11-30 13:49:24 24 4
gpt4 key购买 nike

我正在尝试向我的电影 组件 添加一些 css 规则,但是我遇到了一些问题。出于某种原因,我的“const StyledMovie = styled(MOVIE)”似乎没有任何改变,我哪里出错了?我将不胜感激任何帮助,因为其他一切似乎都在工作。我遇到了一个逻辑错误,这是初学者最难解决的,所以我来到这里,问候!

<html>
<head>
<meta charset="utf-8"></meta>
<title>ICS 211 - React</title>
<script crossorigin src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>

<script src="https://unpkg.com/styled-components/dist/styled-components.min.js"></script>

<link href="https://fonts.googleapis.com/css?family=Lato&display=swap" rel="stylesheet">
<style>
html {
background-color: #f8f8f8;
font-family: 'Roboto', sans-serif;
}
hr {
color: blue;
}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/babel">
const TITLE =() =>{
return <div>
<StyledTitleh1>My Top 3 Movies</StyledTitleh1>
<StyledTitleh3>name</StyledTitleh3>
</div>;
}
const MOVIE =({name,link}) => {



return <div><li >{name}<a href={link}>{link}</a></li></div>
}


const App=({ className })=>(
<div className={className}>

<TITLE />
<ol >


<MOVIE name="Boyz n the Hood: " link="https://www.imdb.com/title/tt0101507/" color="blue"/>
<MOVIE name="The Shawshank Redemption: " link="https://www.imdb.com/title/tt0111161/" color="green" />
<MOVIE name="World War Z: " link="https://www.imdb.com/title/tt0816711/" color="red"/>

</ol>
</div>);

const StyledApp = styled(App)`
background-color: papayawhip;

box-shadow: 0px 0px 5px gray;

padding: 10px;
`;
const StyledTitleh1 = styled.h1`
color: blue;
font-family: sans-serif;
`;

const StyledTitleh3 = styled.h3`
color: red;
font-family: courier;`;

const StyledMovie = styled(MOVIE)`
padding: 10px;
color: ${props => props.color};

`;


ReactDOM.render(<StyledApp />, document.getElementById('container'));

</script>
</body>
</html>

最佳答案

创建后您没有在代码中使用 StyledMovie

更改 MOVIE 组件以使用 styled-component 中的 className 属性

const `MOVIE` =({name,link, className}) => {    
return <div className={className}><li >{name}<a href={link}>{link}</a></li></div>
}

并且在您的 App 组件中使用 StyledMovie 而不是 MOVIE

const App=({ className })=>(
<div className={className}>

<TITLE />
<ol >


<StyledMovie name="Boyz n the Hood: " link="https://www.imdb.com/title/tt0101507/" color="blue"/>
<StyledMovie name="The Shawshank Redemption: " link="https://www.imdb.com/title/tt0111161/" color="green" />
<StyledMovie name="World War Z: " link="https://www.imdb.com/title/tt0816711/" color="red"/>

</ol>
</div>);

关于javascript - 样式化的 Prop 颜色,无法更改电影名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58576246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com