簡體   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