javascript - 如何在 react-native 中要求下划线

标签 javascript react-native

react-native 提及的变更日志
https://facebook.github.io/react/blog/2015/04/17/react-native-v0.4.html

NPM modules compatibility: There are a lot of libraries on NPM that do not depend on node/browser internals that would be really useful in React Native, such as superagent, underscore, ...



但这对我不起作用。
这就是我通过 package.json 安装的方式
# package.json

 "dependencies": {
   "react-native": "*",
   "underscore": "^1.8.3"
   ...

我确实在 npm 依赖中看到了它
# npm ls
├─┬ react-native@0.8.0
|  ...
├── react-native-navbar@0.7.3
└── underscore@1.8.3

它确实适用于其他一些 react 组件

这就是我的要求
var _ = require('underscore');

但是不行,_未定义

最佳答案

如果您使用的是 ES6 模块(如在 ReactNative 中),正确的方法是使用 import 语句:

import _ from 'lodash'

let text = _.isUndefined(route.rightButtonText) ? 'Default value' : route.rightButtonText;

关于javascript - 如何在 react-native 中要求下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32204313/

相关文章:

javascript - 从本地存储加载数组: result not an array - javascript

javascript - 在 javascript 中声明具有元素 1, 2, 3....n 的数组的最简单方法是什么

javascript - Electron - 为什么与 HTML 文件相比,通过本地主机加载主窗口时会有很大的延迟?

ios - Expo - 减少 iOS 设备上的 PDF 文件大小

reactjs - 使用按钮更改文本颜色

javascript - 我可以告诉 useMemo 跳过其依赖项数组中的空值吗?

javascript - ExpressJs(NodeJs)即发即弃

javascript - 通过单击返回错误的按钮在 Vue 中添加新的组件实例

java - React Native Android 添加包时出错

javascript - React-native 数组检查值是否存在