我试图在我的项目中设置顺风,但这似乎是不可能的。文档说您应该使用yarn add tailwind-rn来安装,然后使用npx setup-tailwind-rn来设置它。这是github页面上的代码示例:
import React from 'react';
import {SafeAreaView, View, Text} from 'react-native';
import {useTailwind} from 'tailwind-rn';
const Hello = () => {
const tailwind = useTailwind();
return (
<SafeAreaView style={tailwind('h-full')}>
<View style={tailwind('pt-12 items-center')}>
<View style={tailwind('bg-blue-200 px-3 py-1 rounded-full')}>
<Text style={tailwind('text-blue-800 font-semibold')}>
Hello Tailwind
</Text>
</View>
</View>
</SafeAreaView>
);
};
export default Hello;我的代码如下所示:
import { StyleSheet, Text, View } from 'react-native';
import {useTailwind} from 'tailwind-rn';
export default function App() {
const tailwind = useTailwind();
return (
<View style={tailwind('text-white')}>
<Text>Open up App.js to start working on your app!</Text>
</View>
);
}代码不会抛出任何错误,但不会产生任何结果。我还检查了tailwind('text-white')的值,它似乎只是一个空对象。为什么不起作用?
发布于 2022-09-01 06:32:14
将此添加到依赖项(package.json)中
"tailwind-react-native-classnames": "^1.5.1",将导入到您的项目页面中,
import tw from "tailwind-react-native-classnames";最后,使用这样的顺风样式,
style={tw`flex-1`}
<View style={[tw`bg-gray-200`, { height: 0.6 }]} />最后你的代码会起作用的。
https://stackoverflow.com/questions/73561465
复制相似问题