【问题标题】:How to use console.log when trying to see an output? [duplicate]尝试查看输出时如何使用 console.log? [复制]
【发布时间】:2021-09-10 12:12:15
【问题描述】:

例如,声明activeTabIndex

如何查看我是否设置了 activeTabIndex 事件?

代码如下:

 <TouchableOpacity onPress={() => setActiveTabIndex(0)} style={{ width: Dimensions.get("window").width / 4, padding: 5, alignItems: "center" }}>
          <Home height={30} width={22} fill={activeTabIndex == 0 ? "blue" : "#d4e6f1"} />
        </TouchableOpacity>

在哪里写console.log(activeTabIndex)什么的)

【问题讨论】:

  • {activeTabIndex} 在 JSX 开始和结束标记之间...
  • 在开发者工具上,console.log(activeTabIndex) 不起作用
  • 您不必使用console.log,只需在HTML 中使用{activeTabIndex},该值就会打印在HTML 中。
  • setActiveTabIndex函数中有console.log(whateverVarIsPassed)
  • 这没有任何意义。 - 如果需要,您可以执行 console.log(setTabIndex (activeTabIndex)) 并返回 tabIndex,但反之则不行

标签: javascript react-native


【解决方案1】:
  1. 您可以将 activeTabIndex 绑定到您的 JSX 模板,例如。 {activeTabIndex}
  2. 您可以在 setActiveTabIndex() 方法中添加一个 console.log(index) 来查看它是否被触发。

【讨论】:

  • 这基本上是cmets对问题的巩固。这个问题不值得回答,应该删除
  • 我只是无法理解.. 我的意思是我想写入控制台本身。 setActiveTabIndex() 这只是设置状态,如果我写 setTabIndex(console.log(activeTabIndex) 是没有意义的,因为我在那里设置,如果我写这个,它不会被设置
猜你喜欢
  • 2019-06-16
  • 2012-11-09
  • 1970-01-01
  • 2019-11-23
  • 2011-11-21
  • 1970-01-01
  • 2021-11-01
  • 2014-07-19
  • 2021-05-24
相关资源
最近更新 更多