nativewind在expo应用中的奇怪行为,一半有效,一半无效

问题描述 投票:0回答:1

这很奇怪,这是一个到底发生了什么的例子

enter image description here

import { View, Text } from "react-native";
import { StyleSheet } from "react-native";

export default function EditScreenInfo({ path }: { path: string }) {
  return (
    <>
      <View className='mt-12 items-center'>
        <Text>Open up the code for this screen:</Text>
      </View>
      <View className='mt-12'>
        <Text className='text-center'>
          Change any of the text, save the file, and your app will automatically
          update.
        </Text>
      </View>
    </>
  );
}

问题是,如果你将

mt-12
中的12更改为任何其他数字,mt将停止工作

text-center
也不起作用

enter image description here

import { View, Text } from "react-native";
import { StyleSheet } from "react-native";

export default function EditScreenInfo({ path }: { path: string }) {
  return (
    <>
      <View className='mt-12 items-center'>
        <Text>Open up the code for this screen:</Text>
      </View>
      <View className='mt-10'>
        <Text className='text-center'>
          Change any of the text, save the file, and your app will automatically
          update.
        </Text>
      </View>
    </>
  );
}

看到了吗?我变了

<View className='mt-12'>
  <Text className='text-center'>
     Change any of the text, save the file, and your app will automatically
     update.
  </Text>
</View>

<View className='mt-10'>
  <Text className='text-center'>
     Change any of the text, save the file, and your app will automatically
     update.
  </Text>
</View>

className='mt-12'
className='mt-10'

它停止工作,无论我输入什么数字,它只适用于 mt-12,为什么?

"nativewind": "^4.1.23",
"tailwindcss": "^3.4.16"

根据文档实施一切

我尝试通过 npx expo start --clear 不带缓存重新启动,但在那之后 mt-10 仍然不适用

javascript react-native tailwind-css nativewind
1个回答
0
投票

事实证明,在 tailwind.config.js 的文档中,没有将样式应用到组件文件夹的路径,这就是问题所在

/** @type {import('tailwindcss').Config} */
module.exports = {
  // NOTE: Update this to include the paths to all of your component files.
  darkMode: "class",
  content: ["./app/**/*.{js,jsx,ts,tsx}", "./components/**/*.{js,jsx,ts,tsx}"],
  presets: [require("nativewind/preset")],
  theme: {
    extend: {},
  },
  plugins: [],
};
  • 已添加
    "./components/**/*.{js,jsx,ts,tsx}"

注意

© www.soinside.com 2019 - 2024. All rights reserved.