1.定义随机颜色函数
function rgb() {//rgb颜色随机
const r = Math.floor(Math.random() * 256);
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);
return `rgb(${r},${g},${b})`;
}
2.给按钮一个点击切换颜色事件
const qie = () => {
store.dispatch({ type: 'GAI', palyout: rgb() })
}
<div className='login-qie' onClick={() => { qie() }}>切换主题</div>
3.在store文件中定义该事件逻辑
case 'GAI':
return {
...state,
color: palyout
}
break
if (!state) {
return {
list: [],
color: 'red'
}
}
let { type, palyout } = actions