react-native - 如何通过点击按钮更改输入文本上的变量?反应原生
问题描述
该图像显示了代码的作用。当我点击 + 或 - 按钮时,我希望输入文本中的文本发生变化。我怎样才能做到这一点?
function Cerveja(props) {
const [count,setCount] = useState(0);
<View style={{flex: .1}}>
<Button
onPress={()=>setless(count*1)}
title="-"
color="#841584"
/>
</View>
<View style={{flex: 0.11}}>
<TextInput
textAlign={'center'}
style={{height: 40}}
placeholder={'0'}
onChangeText={(count) => setCount(count)}
keyboardType={'numeric'}
/>
</View>
<View style={{flex: .1}}>
<Button
onPress={()=> setCount(count*1+1)}
title="+"
color="#841584"
/>
</View>
<View style={{flex: .19}}>
<Text textAlign={'center'}>R$ {parseFloat((count*1*props.price).toFixed(2))}</Text>
</View>
</View>
请帮忙!
解决方案
这可能适用于“+”按钮
onPress={()=> setCount(count+1)}
这对于“-”按钮
onPress={()=> setCount(count-1)}
推荐阅读
- python - 远程地址的主机接口或路由
- drupal-7 - 如何在 drupal 7 中为用户活动创建报告
- jquery-ui - 了解 jQuery UI 按钮小部件
- javascript - 无法使用 webpack 4 转换 .marko 文件
- java - 如何使用 lambda 表达式创建满足条件的数组列表
- highcharts - Highchart Y 轴刻度值缺失
- bash - 丢失时在文件末尾添加分号
- java - maven 复制依赖与定义依赖
- c++ - 如何使用 libgit2 编写正确的 git pull
- java - 当我合并使用 Log4j 2 的库时,java.util.logging 停止工作