我无法从其他模块检索值

亚哈·钱德鲁

我是本机反应的新手。我不知道如何在两个模块之间传递值。如果你能帮我一下,我会很客气的。另一个疑问是,在代码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;

这是我的错误

这是我的项目结构

乌默赛义德

您已经提到了直到文件夹的路径并且想要访问文件。这是因为您收到错误Try with './localserver/data'

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章