【问题标题】:React-Native | ReferenceError: defaultStyles is not defined反应原生 | ReferenceError: defaultStyles 未定义
【发布时间】:2021-10-14 07:54:31
【问题描述】:

我正在尝试一个应用程序的原型,它也需要在网络浏览器上兼容。但是,我在浏览器上运行它时遇到了困难,而它实际上可以在 android 模拟器中运行。

我收到以下错误:ReferenceError: defaultStyles is not defined

这是我目前的代码。我看不出我哪里出错了,因此以更多的知识转向你。

import { StyleSheet } from "react-native";

export default defaultStyles = StyleSheet.create({
    textInput: {
        height: 40,
        margin: 12,
        borderWidth: 1,
        padding: 10,
        width: 200
    },

    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center'
    },

    centerHorizontal: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center'
    },

    centerVertical: {
        flex: 1,
        justifyContent: 'center',
        flexDirection: 'column'
    },

    centerCenter: {
        flex: 1,
        justifyContent: 'center',
        flexDirection: 'column',
        alignItems: 'center'
    }


});

【问题讨论】:

  • 尝试改变` export defaultStyles = StyleSheet.create({` to export default StyleSheet.create({ and use import styles from '../path/filename';
  • 您能了解一下您是如何导入默认样式的吗?

标签: reactjs react-native react-redux


【解决方案1】:

将导出更改为:

export default StyleSheet.create({
....
});

【讨论】:

    【解决方案2】:

    将导出更改为const defaultStyles = StyleSheet.create({

    最终使用export { defaultStyles }

    在页面import {defaultStyles} from '../path/filename'

    使用style={defaultStyles.container}

    使用export default StyleSheet.create({

    在页面import [defaultStyles/ANY NAME] from '../path/filename'

    使用style={defaultStyles.container}

    【讨论】:

      【解决方案3】:

      我建议你说:

      const defaultStyles = Stylesheet.create({});
      
      export default defaultStyles;
      

      【讨论】:

        猜你喜欢
        • 2019-07-30
        • 2017-06-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-21
        • 2023-04-06
        • 1970-01-01
        相关资源
        最近更新 更多