React native 反应本机:”;此.props.imageSource“;问题

React native 反应本机:”;此.props.imageSource“;问题,react-native,npm,rendering,react-native-android,imagesource,React Native,Npm,Rendering,React Native Android,Imagesource,当我使用dynamic image src并启动NPM时,出现以下错误: TargetModuleName.“this.props.imageSource”,:message:“无法解析模块…” 但是当我把constURL放进去时,它就可以正常工作了 这是我的代码: import React, { Component } from 'react'; import { StyleSheet, Text, View, ScrollView, Image } from 'react-native';

当我使用dynamic image src并启动NPM时,出现以下错误:

TargetModuleName.“this.props.imageSource”,:message:“无法解析模块…”

但是当我把constURL放进去时,它就可以正常工作了

这是我的代码:

import React, { Component } from 'react';

import { StyleSheet, Text, View, ScrollView, Image } from 'react-native';

import CustomImage from './CustomImage';

export default class ContentContainer extends React.Component {
  render() {
    return (
      <View style={styles.contentContainer}>

          <View style={styles.col2}>
              <CustomImage imageSource={'../img/shirts.jpg'} />
          </View>
          <View style={styles.col1}></View>
          <View style={styles.contentBanner}></View>

      </View>
    );
  }
}

//------------ CustomImage.js -----------------------
import React, { Component } from 'react';
import PropTypes from 'react';
import { StyleSheet,AppRegistry, Text, View, ScrollView, Image } from 'react-native';


export default class CustomImage extends React.Component {
  render() {
    return (
        <Image source={require('this.props.imageSource')} style={styles.Image} />


    );
  }
}
import React,{Component}来自'React';
从“react native”导入{样式表、文本、视图、滚动视图、图像};
从“/CustomImage”导入CustomImage;
导出默认类ContentContainer扩展React.Component{
render(){
返回(
);
}
}
//------------CustomImage.js-----------------------
从“React”导入React,{Component};
从“react”导入proptype;
从“react native”导入{样式表、AppRegistry、文本、视图、滚动视图、图像};
导出默认类CustomImage扩展React.Component{
render(){
返回(
);
}
}

首先,您的语法不正确。应该如下所示

require(this.props.imageSource)
即使修复了该语法,它也不会起作用,因为本地映像源不能是动态的,因为它们需要在构建时编译。因为需要知道映像的路径

你可以在网上更多地了解它