【问题标题】:can't find variable veiw找不到变量视图
【发布时间】:2018-08-29 13:16:00
【问题描述】:

我有以下来自 youtube 教程的代码(我刚刚开始使用 react native):

import React, {Component} from 'react';
import { Text, StyleSheet, View, TextInput, ScrollView, TouchableOpacity} from 'react-native';


type Props = {};
export default class Main extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>

        <Veiw style={styles.header}>
            <Text style={styles.headerText}>
                Todo List
            </Text>
        </Veiw>

        <ScrollView style={style.ScrollContainer}>


        </ScrollView>

        <Veiw style={style.footer}>
            <TextInput styles={styles.TextInput} placeholder='>Todo' placeholder = 'white' underlineColorAndroid = 'transparent'>

            </TextInput>
        </Veiw>
      </View>
    );
  }
}

但是当我在我的 android 模拟器上运行它时,我收到以下错误消息:

ReferenceError 找不到变量:Veiw

我知道错误很清楚,但我在应用程序的开头导入了 Veiw,为什么没有注册?

【问题讨论】:

  • 你只是没有导入“Veiw”,你导入了“View”,这样写才是对的。
  • 别忘了把最有用的答案标记为正确答案!

标签: android react-native


【解决方案1】:

我相信你拼错了“视图”,试试这个:

import React, {Component} from 'react';
    import { Text, StyleSheet, View, TextInput, ScrollView, TouchableOpacity} from 'react-native';


    type Props = {};
    export default class Main extends Component<Props> {
      render() {
        return (
          <View style={styles.container}>

            <View style={styles.header}>
                <Text style={styles.headerText}>
                    Todo List
                </Text>
            </View>

            <ScrollView style={style.ScrollContainer}>


            </ScrollView>

            <View style={style.footer}>
                <TextInput styles={styles.TextInput} placeholder='>Todo' placeholder = 'white' underlineColorAndroid = 'transparent'>

                </TextInput>
            </View>
          </View>
        );
      }
    }

【讨论】:

    【解决方案2】:

    这只是一个错字,有时会发生这种情况,只需将“Veiw”更改为“View”即可。由于您是 React Native 的新手,您可以随时前往 official documentation 并确保您正在使用的组件在导入它们时确实存在(官方组件总是在“import 'react-native'”行中导入)。

    这些都是 React Native 的官方组件:

    import { Text, StyleSheet, View, TextInput, ScrollView, TouchableOpacity} from 'react-native';
    

    在文档中,您总能找到组件、它们的道具以及如何使用它们。还有一些有用的指南,我建议你也从它们开始。

    【讨论】:

      【解决方案3】:

      您在四个地方拼错了 View,修复它可以消除错误。

      【讨论】:

        【解决方案4】:

        只是您应该将 veiw 更改为 View。

        【讨论】:

          猜你喜欢
          • 2019-09-02
          • 1970-01-01
          • 2023-03-22
          • 1970-01-01
          • 1970-01-01
          • 2018-06-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多