reactjs - 状态的属性值没有保存在 const 变量中?
问题描述
我是 React 的新手,我制作了 2 个状态对象,每个对象都有一个属性,然后我尝试将属性的值保存在 const 变量中,我正确地获取了第一个状态的值,但由于未知原因,其他的值没有显示在控制台中日志
这是2个州的代码
state = {
count: 23,
};
stateTwo = {
number: 22
};
这些是在控制台日志中调用值的 2 个函数
changNumber() {
console.log("this is nmbr frm state: " + this.stateTwo.number);
const { count } = this.stateTwo;
console.log("this is : " + count);
return count === 0 ? "ZERO" : count;
}
formatCount() {
console.log("this is nmbr frm state: " + this.state.count);
const { count } = this.state;
console.log("this is : " + count);
return count === 0 ? "ZERO" : count;
}
解决方案
推荐阅读
- coq - 目标中存在下的重写等价
- android - 使用 kotlin 合成时,在 Fragment 的 onViewCreated 上设置视图属性(setText 和 setOnClickListener)不起作用
- javascript - QML 和 RSA 加密
- xl-deploy - 如何在 XLDeploy 中查看已部署构建的占位符值
- javascript - MMM-yyyy 格式的 AMchart 数据
- r - 重置 R 闪亮的 actionButton 以多次使用它
- java - 在自己的构造函数中引用 java 类
- reactjs - 玩笑模拟导致警告:正确的大小写,标签无法识别和未知属性
- ruby-on-rails - Windows 上的 PostgreSQL 应用程序无法正常工作
- google-sheets - 如果值大于 0 标记线绿色