我是TypeScript的新手.我在渲染方法中显示this.state.something或将其分配给函数内的变量时出现问题.
看看最重要的一段代码:
interface State {
playOrPause?: string;
}
class Player extends React.Component {
constructor() {
super();
this.state = {
playOrPause: 'Play'
};
}
render() {
return(
<div>
<button
ref={playPause => this.playPause = playPause}
title={this.state.playOrPause} // in this line I get an error
>
Play
</button>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
错误说:"[ts]属性'playOrPause'在'ReadOnly <{}>'类型中不存在.
我试图将playOrPause属性声明为一种字符串,但它不起作用.我在这里错过了什么才能让它发挥作用?
我想知道是否有一种方法可以用sass编写媒体查询,因此我可以在例如300px至900px之间给出某种样式
在CSS中看起来像这样
@media only screen and (min-width: 300px) and (max-width: 900px){
}
Run Code Online (Sandbox Code Playgroud)
我知道我会写
@media (max-width: 900px)
Run Code Online (Sandbox Code Playgroud)
在无礼,但如何使范围?