gpt4 book ai didi

android - react-native 错误找不到变量 : styles

转载 作者:搜寻专家 更新时间:2023-11-01 08:19:47 25 4
gpt4 key购买 nike

我是 React-native 的新手。我试图在我的组件中设置 View 元素的样式,并且在尝试应用样式标签时,出现以下错误:
笔记 :我在单独的 js 文件中的样式标签
在 styles.js 中

import {Dimensions} from 'react-native';

const DEVICE_WIDTH= Dimensions.get('window').width;
const DEVICE_HEIGHT= Dimensions.get('window').height;

export default {
container:{
backgroundColor: 'white',
flex:1 ,
width: DEVICE_WIDTH,
height: DEVICE_HEIGHT,
}
};

在 Main.js 文件中

import React,{ Component } from 'react';
import { Router,Scene,Actions} from "react-native-router-flux";
import {View} from 'react-native';

import styles from './styles.js'

class Main extends Component{

render(){
return(
<View style={styles.container} >
<Text>
Hello pages
</Text>
</View>

);
}
}

export default Main;

错误屏幕: error

最佳答案

你需要像这样使用 StyleSheet.create

export default StyleSheet.create({
container: {
backgroundColor: 'rgb(249, 250, 252)',
},
})

还要检查您是否正确导入了 styles.js,并且您也不需要像这样将 .js 放入导入中

import styles from './styles'

关于android - react-native 错误找不到变量 : styles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52853888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com