繁体   English   中英

尝试导入错误:'styles' 未从 './styles' 导出

[英]Attempted import error: 'styles' is not exported from './styles'

我正在尝试从style.js文件中导入 styles 并且该文件包含以下代码

    const export styles = {
    border: 'solid',
    textAlign : 'center',
    boxShadow : '2px 2px'
  }

但它在该文件中显示以下错误

'export' is not allowed as a variable declaration name.

但是当我添加export关键字时,如下代码所示

    const styles = {
    border: 'solid',
    textAlign : 'center',
    boxShadow : '2px 2px'
  }
    export default styles;

并尝试将我的组件导入为

import * as styles from "./styles";

<div style={styles.styles}>
          Style
</div>

我收到以下错误

Attempted import error: 'styles' is not exported from './styles'.

我该如何解决?

使用这种方式style.js

import { StyleSheet } from 'react-native';

export const styles = StyleSheet.create({

});

并尝试将我的组件导入为

import styles from "./styles";

尝试默认导出

 const styles = {
    border: 'solid',
    textAlign : 'center',
    boxShadow : '2px 2px'
  }
  export default styles;

我尝试了下面对我有用的代码

 export const externalStyles = {
    color : 'red',
    backgroundColor: 'green'
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM