如何将图像导入到我的 React Native 应用程序中?

erv*_*erv 1 javascript reactjs react-native

我是 React Native 的新手,我正在尝试通过以下方式在我的应用程序中包含图像:

function Interactions(props) {
    return (
        <View>
            <Image source={require('./assets/comment_32.png')} />
            <Text>{props.info.replies}</Text>
        </View>
    );
}
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误 -TypeError: Failed to construct 'Image': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

Mar*_*tar 7

您需要从react-native导入Image组件。

import { Image } from 'react-native';

Run Code Online (Sandbox Code Playgroud)