我无法从其他模块检索值

时间:2019-03-22 06:24:52

标签: react-native

我是新来的本地人。我不知道如何在两个模块之间传递值。如果您能帮助我,那将非常好。另一个疑问是,在代码A 中,当为文本输入编写样式值时,为什么有四个花括号?

代码A

import React, { Component } from 'react';
import { AppRegistry, Text, TextInput, View,Dimensions} from 'react-native';
import data from './localserver';

export default class PizzaTranslator extends Component {
  constructor(props) {
    super(props);
    this.state = {text: ''};
  }

  render() {
    return (

    <View style={{flex: 1, flexDirection: 'column',justifyContent:'space-around',alignItems:'center'}}>
      <TextInput
            style={{height: 40}}
            placeholder="Enter your mobile no"
            placeholderTextColor={data.details}
          />
      <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
      <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
    </View>

      );
  }
}

AppRegistry.registerComponent('AwesomeProject', () => PizzaTranslator);

代码B

import React from 'React'
var details = {
  primarysColor: '#FFC12E',
  secondarysColor: '#111E27'
}

export default details;

this is my error

This is my project structure

2 个答案:

答案 0 :(得分:1)

您提到了直到文件夹的路径 并想访问文件。这是因为您遇到错误 尝试使用“ ./localserver/data”

如果不想提及/ data,则需要在localserver文件夹下添加index.js文件,并在索引文件中导出数据文件

答案 1 :(得分:0)

  

在代码A中写文字输入样式的值时为什么会有   四个大括号

  • 前两个花括号用于JSX,因为一旦您开始在JSX内写入JS(您的情况下的样式对象),就需要将它们封装在{ }
  • 之间
  • 内部花括号用于样式object

关于在模块之间传递数据……data.js语句中缺少文件名import

import data from './localserver/data';