React Native

时间:2017-02-09 12:04:46

标签: react-native react-native-android react-native-image

<Image source={require('./cat.jpeg')}/>

我在渲染函数中有这一行,当我运行代码时,我在此行收到错误意外的令牌。如何解决这个问题? 图像cat.jpeg与当前组件位于同一文件夹中。

以下是完整代码:

'use strict'
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Navigator,
  Text,
  View,
  Image
} from 'react-native';

import { Actions } from 'react-native-router-flux';


export default class HomeScreen extends Component{



  render() {
    return (
            <View style={styles.container}>
            <View style={styles.rowcontainer}>
            // <Image style={{width: 50, height:50}}
            // source={{uri: 'https://facebook.github.io/react/img/logo_small.png'}}/>
            <Image source={require('./cat.jpeg')}/>

            <Text onPress={Actions.MarkAttendance}style={styles.welcome}>
          Mark Attendance
        </Text>


        <Text onPress={Actions.AttendanceDetails}style={styles.welcome}>
          View Attendance
        </Text>

        </View>

        <View style={styles.rowcontainer}>

        <Text onPress={Actions.Test}style={styles.welcome}>
          Test
        </Text>


        <Text onPress={Actions.NewActivation}style={styles.welcome}>
          New Activation
        </Text>

        </View>
        <View style={styles.rowcontainer}>

        <Text onPress={Actions.PendingAttendance}style={styles.welcome}>
          Pending Attendance
        </Text>


        <Text onPress={Actions.Checkout}style={styles.welcome}>
          Checkout
        </Text>

        </View>
        <View style={styles.rowcontainer}>

        <Text onPress={Actions.Settings}style={styles.welcome}>
          Settings
        </Text>

        <Text style={styles.welcome}>
          Logout
        </Text>

        </View>
        </View>
       )

  }


}


var styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop:50,
    backgroundColor: '#FFFFFF',
  },
  rowcontainer:{
    alignItems:'stretch',
    flexDirection:'row',
    justifyContent:'space-between',
    margin: 10,
  },
  welcome:{
    fontSize:15,
  }
});

1 个答案:

答案 0 :(得分:1)

使用类似HTML的语法时,不能使用//注释掉渲染函数内的代码片段。 而是尝试在{}内包装你想要评论的任何内容并使用那里的javascript块评论 例如

{/*
    <Image
        source=.../>
*/}