带有响应本机的奇怪StyleSheet错误

时间:2018-10-23 13:09:24

标签: javascript react-native stylesheet

我有一个包含2个类的javascript文件。对于这两个类,我都有单独的StyleSheets。如下图所示:

export class PageOne extends Component {
   render(){
      return(
        <View style={pageOne.container}>
        ...
        </View>
   )
}

const pageOne = StyleSheet.create({
    container: {
      backgroundColor: '#FFDD33',
      flex: 1,
      width: '100%',
      flexDirection: 'row',
    },
    ...
});

export class PageTwo extends Component {
    render(){
      return(
        <View style={pageTwo.container}>
        ...
        </View>
      )
   }

const pageTwo = StyleSheet.create({
   container: {
     *Error ^*
   backgroundColor: '#FFFFFF',
   flex: 1,
   width: '100%',
 },
 ...
});

Error Image

1 个答案:

答案 0 :(得分:1)

我认为您错过了}关闭您的PageOne和PageTwo类组件的情况。

尝试一下:

export class PageOne extends Component {
   render() {
        return(
            <View style={pageOne.container}>
            ...
            </View>
        );
    }
}

const pageOne = StyleSheet.create({
    container: {
      backgroundColor: '#FFDD33',
      flex: 1,
      width: '100%',
      flexDirection: 'row',
    },
    ...
});

export class PageTwo extends Component {
    render(){
        return(
            <View style={pageTwo.container}>
                ...
            </View>
        )
    }
}

const pageTwo = StyleSheet.create({
   container: {
     *Error ^*
   backgroundColor: '#FFFFFF',
   flex: 1,
   width: '100%',
 },
 ...
});