1.代码:
export function getRandomColor() {
function getRandomInt(max: number) {
const randomInt = Math.floor(Math.random() * max)
const hexString = randomInt.toString(16).padStart(2, '0')
return hexString
}
const red = getRandomInt(256)
const green = getRandomInt(256)
const blue = getRandomInt(256)
return `#${red}${green}${blue}`
}
2.调用 getRandomColor() 这个方法就好