Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用道具不需要';不行&引用;在..处的呼叫无效“;_Javascript_Image_React Native_Require - Fatal编程技术网

Javascript 使用道具不需要';不行&引用;在..处的呼叫无效“;

Javascript 使用道具不需要';不行&引用;在..处的呼叫无效“;,javascript,image,react-native,require,Javascript,Image,React Native,Require,我不明白为什么这个代码不起作用 const UserCard = props => { return ( <View style={styles.card}> <View style={{flex: 0.33}}> <Image source={require(props.user.image)} style={{width: 100, height: 100}}/> &

我不明白为什么这个代码不起作用

const UserCard = props => {
    return (
      <View style={styles.card}>
          <View style={{flex: 0.33}}>
            <Image source={require(props.user.image)} style={{width: 100, height: 100}}/>
          </View>
          <View style={{flex: 0.66}}>
            <Text>bb</Text>
          </View>
      </View>
    );
}

const styles = StyleSheet.create({
  card: {
    flexDirection: 'row',
    backgroundColor: 'green'
  },
});


export default UserCard;

你能告诉我们你是如何在你的
UserCard
组件中传递
user
的吗?@KishanBharda I编辑代码,让你看到变量user@Cookie对于静态图像,我不知道。但还有一个问题是
UserCard
组件在另一个文件中?是@KishanBharda
return (
   const user_image = require(props.user.image);
   ... 
      <Image source={user_image} style={{width: 100, height: 100}}/>
   ...
return (
   const user_image = props.user.image;
   ... 
      <Image source={require(user_image)} style={{width: 100, height: 100}}/>
   ...
const users = [
      {
        "image" : "Assets/test/fernando.jpg",
        "name" : "Fernando",
        "description" : "General Manager",
      },
      {
        "image" : "Assets/test/daniel.jpg",
        "name" : "Daniel",
        "description" : "CEO",
      },
      {
        "image" : "Assets/test/joan.jpg",
        "name" : "Joan",
        "description" : "Manager",
      },
    ];

class HomeScreen extends React.Component {
   ...
   render() {
       return (
         <SafeAreaView style={styles.container}>
           <ScrollView
             style={styles.container}
             contentContainerStyle={styles.contentContainer}>
             { typeof users === 'object' && users.length > 0 && (users.map((user, index) => {
              return (
                  <View key={index} style={{flex: 1, backgroundColor: 'red'}}>
                    <UserCard user={user} />
                  </View>
              )})
            ) }  
           </ScrollView>
         </SafeAreaView>
       );
     }