簡體   English   中英

react-native:導入后找不到變量樣式表

[英]react-native: Can't find variable Stylesheet after importing it

我對什么應該是一個簡單的修復有點困惑。 我在版本 0.27.2 上運行 react-native 項目,並且我的所有ios.js文件都成功導入樣式表,除了一個。

導入看起來像這樣:

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

import {
  Cell,
  CustomCell,
  Section,
  TableView
} from 'react-native-tableview-simple';

const styles = Stylesheet.create({
  container: {
      backgroundColor: 'rgb(20,25,30)',
    }
  }
);

Stylesheet.create({}) function 最終導致錯誤Can't find variable Stylesheet被拋出。 但是,我已經在具有相同導入的所有其他文件中以相同的方式聲明了 styles,並且那些呈現 styles 沒有錯誤。

此文件中唯一不同的是聲明了多個類。 我是 React 新手,所以我不知道這是否會導致問題。 有誰知道是什么原因造成的?

你混合了情況,你需要寫

const styles = StyleSheet.create({

就像您在導入時為其命名一樣。

我剛遇到同樣的問題,發現類型在不同的模塊中。 如果您有正確的大小寫(樣式表)但仍然無法正常工作,則很可能您沒有安裝類型模塊。 只需在 cmd 中執行這一行 -

npm install --save @types/react-native

它應該可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM