组件
import React, { useState, useEffect } from 'react'
import styles from './style.less'
import { getRandomIntInclusive } from './Tools/index'
const index = () =>
{
const [literal, setLiteral] = useState('优')
useEffect(() =>
{
setInterval(() =>
{
let random = getRandomIntInclusive(0, 3)
setLiteral(random === 1 ? '优' : random === 2 ? '良' : '差')
}, 1000)
}, [])
return (
<div className={styles.container}>
<span style={literal === '优' ? { color: '#19BF54' } : literal === '良' ? { color: '#E38F35' } : literal === '差' ? { color: '#EB2E24' } : null}>{literal}</span>
</div>
)
}
export default index
getRandomIntInclusive
export function getRandomIntInclusive (min, max)
{
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}