简体   繁体   English

单击按钮时该功能不起作用

[英]The function does not work when I click the button

My buttons:我的按钮:

<div className="ingrBtns">
    <button className="ingrBtn" 
            onClick={() => addRemoveIngredient('add','lettuce')}>
            +
    </button>
    <button className="ingrBtn" 
            onClick={() => addRemoveIngredient('remove','lettuce')}>
            -
    </button>
    <div className="price"> 
         &nbsp;&nbsp;&nbsp;${(state.lettuce*0.5).toFixed(2)}
    </div>
</div>

The function does not work when I click the button.当我单击按钮时,该功能不起作用。 Where is the problem ?问题出在哪儿 ?

You must use the keyword "this"您必须使用关键字“this”

<div className="ingrBtns">
    <button className="ingrBtn" onClick={() => this.addRemoveIngredient('add','lettuce')}>+</button>
    <button className="ingrBtn" onClick={() => this.addRemoveIngredient('remove','lettuce')}>-</button>
    <div className="fiyat"> &nbsp;&nbsp;&nbsp;${(this.state.lettuce*0.5).toFixed(2)}</div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM