我正在尝试学习React并在网站上遇到此代码:https://www.reactenlightenment.com/react-state/8.2.html
我理解代码的作用,但无法理解changeMood函数中的参数'a'是什么。我删除它后运行代码,代码运行良好。
var MoodComponent = React.createClass({
getInitialState: function() {
return {mood: ':|'};
},
changeMood:function(event, a){
const moods = [':)',':|',':('];
const current = moods.indexOf(event.target.textContent);
this.setState({mood: current === 2 ? moods[0] : moods[current+1]});
},
render: function() {
return (
<span style={{fontSize:'60',border:'1px solid #333',cursor:'pointer'}}
onClick={this.changeMood}>
{this.state.mood}
</span>
)
}
});
答案 0 :(得分:0)