简体   繁体   English

为什么 tailwind css 没有在 react-native 中作为样式应用?

[英]Why tailwind css is not applying as style in react-native?

Tailwind CSS is being used in my react-native project. Tailwind CSS 正在我的 react-native 项目中使用。 Under the Touchable opacity i am using a image and a title and multiple of them are passed through the components props.在 Touchable 不透明度下,我使用了一个图像和一个标题,其中的多个通过组件道具传递。 Like below:像下面这样:

import { View, Text, ScrollView } from 'react-native'
import React from 'react'
import CatagoryCard from './CatagoryCard'

const Catagories = () => {
  return (
    <ScrollView horizontal
    showsVerticalScrollIndicator={false}
    contentContainerStyle={{
      paddingHorizontal:15,
      paddingTop:10
    }}>
      <CatagoryCard imgUrl = "https://i.ibb.co/ZYvGfFY/Untitled-design-7.png" title = " TEST 1"/>
      <CatagoryCard imgUrl = "https://i.ibb.co/ZYvGfFY/Untitled-design-7.png" title = " TEST 2"/>
      <CatagoryCard imgUrl = "https://i.ibb.co/ZYvGfFY/Untitled-design-7.png" title = " TEST 3"/>

    </ScrollView>
  )
}

export default Catagories

And the catagoryCard components looks like this: catagoryCard 组件如下所示:

import {Text, TouchableOpacity,Image } from 'react-native'
import React from 'react'

const CatagoryCard = ({imgUrl,title}) => {
  return (
    <TouchableOpacity>
        <Image
            source = {{uri:imgUrl}}
            resizeMode = 'contain'
            className = "h-20 w-20 rounded flex-2"
        />
      <Text>{title}</Text>
    </TouchableOpacity>
  );
};

export default CatagoryCard;

The image was not appearing in the card section using the component code.该图像未出现在使用组件代码的卡片部分中。 But when I used但是当我用

style={{height: 50, width: 50}}

ubder the image component is working perfectly.在图像组件下工作完美。 But my question is using tailwindcss i am also applying the style of h & w.但我的问题是使用 tailwindcss 我也在应用 h & w 的风格。 But why they are not working?但为什么他们不工作? Why do I have to use the style separately to make the component work?为什么我必须单独使用样式才能使组件工作?

Actually I did the mistakes in the tailwind.config file.实际上我在 tailwind.config 文件中犯了错误。 I did components and screens in separate folder but mentioned about the screens folder only in tailwind.config.js.我在单独的文件夹中做了组件和屏幕,但只在 tailwind.config.js 中提到了屏幕文件夹。

Make sure you includes all your UI related folders are specifically declared on the tailwind config file.确保您包括所有与 UI 相关的文件夹,这些文件夹在 tailwind 配置文件中明确声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM