【发布时间】:2018-10-10 06:39:14
【问题描述】:
我是 Reactjs 的新手,我正在制作一个增加和减少数量的函数。我的代码如下:
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
quantity: 1,
show: true,
max:5,
min:0
};
}
IncrementItem = () => {
if(this.state.quantity > 9) {
}else {
this.setState({
quantity: this.state.quantity + 1
});
}
}
DecreaseItem = () => {
if(this.state.quantity <= 1) {
}else {
this.setState({ quantiy: this.state.quantity - 1 });
}
}
ToggleClick = () => {
this.setState({ show: !this.state.show });
}
render() {
return (
<div>
<button onClick={this.IncrementItem}>+</button>
<input className="inputne" value={this.state.quantity} />
<button onClick={this.DecreaseItem}>-</button>
</div>
);
}
我的问题是:
浏览器出现错误: 警告:失败的道具类型:您向没有
onChange处理程序的表单字段提供了value道具我无法从 View 更改输入值。
请告诉我如何解决。感谢您的帮助。
【问题讨论】:
标签: reactjs