Reactjs 从图像池中选择背景图像
我对react native还不熟悉,我想知道如何编写/构建应用程序的起始页,以便在每次启动应用程序时(针对同一用户)显示不同的图像Reactjs 从图像池中选择背景图像,reactjs,react-native,Reactjs,React Native,我对react native还不熟悉,我想知道如何编写/构建应用程序的起始页,以便在每次启动应用程序时(针对同一用户)显示不同的图像 我有一组可用的图像,我希望开始页面在用户每次启动应用程序时显示不同的随机背景图像。您可以在数组中设置背景图像uri,并使用0到数组长度之间的随机生成器进行渲染 const Images = ['uri 1', 'uri 2', 'uri 3', 'uri 4'] componentDidMount() { const randomNumber = Math.
我有一组可用的图像,我希望开始页面在用户每次启动应用程序时显示不同的随机背景图像。您可以在数组中设置
背景图像uri
,并使用0到数组长度之间的随机生成器进行渲染
const Images = ['uri 1', 'uri 2', 'uri 3', 'uri 4']
componentDidMount() {
const randomNumber = Math.floor(Math.random() * Images.length);
this.setState({currentImageIndex: randomNumber})
}
render() {
return (
<ImageBackground source={{uri: Images[this.state.currentImageIndex]}}>
//... Other stuff
</ImageBackground>
)
}
const-Images=['uri1','uri2','uri3','uri4']
componentDidMount(){
const randomNumber=Math.floor(Math.random()*Images.length);
this.setState({currentImageIndex:randomNumber})
}
render(){
返回(
//…其他东西
)
}