react-native - 为什么图像以数字形式导入?

标签 react-native

import image from './image.png';
console.log(image) // returns some number

为什么图像在 React Native 中被导入为数字?

最佳答案

require React Native 中的图像将被映射为数字。
@types/react-native React Native Typescript 声明,我们可以像下面这样显示。

export type ImageSourcePropType = ImageURISource | ImageURISource[] | ImageRequireSource;
...
export type ImageRequireSource = number;
ImageRequireSource只是 number 的别名类型,它可以是 ImageSourcePropType .

关于react-native - 为什么图像以数字形式导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46176383/

相关文章:

xcode - 如何创建 React-Native tvos 项目?

android - react-native run-android build 在没有红屏的情况下启动时崩溃

react-native - React Native 让 android 应用在 genymotion 中加载

javascript - 如何将状态推送到包含特定项目的数组?

ios - React Native - 开关不改变值

reactjs - 即使 flex : 1,React Native 文本输入字段也不会全宽

base64 - 如何在 React Native 中获取图像的 base64

react-native - 如何将我的 React Native Storybook 构建到 Web?

javascript - VSCode 使用 JavaScript 自动导入 React Native

android - Linking.getInitialURL() 在用于深度链接后未被清除