react-native - 视图样式在 React Native 中不起作用
问题描述
在我的代码中使用之前,我是 React Native 的新手const Main = () => { ..}
但是当我更改export default class Main extends React.Component { ..}
为时,会出现问题,例如 View 中的样式不起作用但错误',' expected in style
截图:
我正在使用新版本的 react native
解决方案
您缺少应该使用 return() 方法的 render() 方法。
前任:
export default class LotsOfStyles extends Component {
render() {
return (
<View>
<Text style={styles.red}>just red</Text>
<Text style={styles.bigBlue}>just bigBlue</Text>
<Text style={[styles.bigBlue, styles.red]}>bigBlue, then red</Text>
<Text style={[styles.red, styles.bigBlue]}>red, then bigBlue</Text>
</View>
);
}
}
推荐阅读
- r - 如何使用ggplot为变量绘制三个条形?
- bash - 在 unix 上带有变量的 printf
- c# - 如何使用 MVC 控制器中的操作内的重定向退后两步浏览器历史记录?
- yii2 - Yii2 Select2 也跨越了原始选择
- erlang - 我怎样才能摆脱 Elixir 中的 Enum.reduce
- java - Spring Cloud - Feign - 无法实例化 [feign.Retryer]
- sql - 在一次点击数据库中选择所有多对多记录以及父表
- c# - CacheManager 与 inproc 和 Redis 一起处理,因为背板未同步
- javascript - Javascript 删除“字符串”中的空格
- debugging - 在本地目录中找不到 .gdbinit 文件