gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:36:44 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com