我正在尋找一個按鈕組件,它允許組件的使用者輸入按鈕的標題。我以前看過這項作業,但現在當我嘗試運行代碼時出現錯誤。
錯誤訊息:“文本字串必須在組件內呈現。
應用按鈕代碼:
import React from 'react';
import { StyleSheet, View, Text } from 'react-native-web';
function AppButton({title}) {
return (
<View style={styles.button}>
<Text style={styles.text}>{title}</Text>
</View>
);
}
const styles = StyleSheet.create({
button: {
backgroundColor: "dodgerblue",
borderRadius: 25,
justifyContent: "center",
alignItems: "center",
padding: 15,
width: '100%',
},
text: {
color: "white",
fontSize: 18,
textTransform: 'uppercase',
fontWeight: 'bold',
}
})
export default AppButton;
輸出代碼:
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import AppButton from './components/AppButton';
export default function App() {
return (
<View style={styles.container}>
<AppButton title = "Push Me"/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
uj5u.com熱心網友回復:
從而'react-native'不是匯入'react-native-web'。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/388130.html
標籤:javascript 反应 反应原生
上一篇:通過點擊呼叫獲取
