【发布时间】:2021-04-01 15:12:35
【问题描述】:
我正在尝试制作秒表 (00:00:00:00)。但我的一秒比真正的一秒慢。 我还将 setInterval 10 的值更改为 1,但没有任何改变。当我将其更改为 100 时,它起作用了,时间流逝得更慢了。 (00:00:00:00)=(hh:mm:ss:ms) 这是我的代码的一部分:
const [time, setTime] = useState({
ms: 0,
ss: 0,
mm: 0,
hh: 0
})
let degisenMs = time.ms,
degisenH = time.hh,
degisenM = time.mm,
degisenS = time.ss;
const run = () => {
if (updatedMs === 100) {
updatedS++;
updatedMs = 0
}
if (updatedS === 60) {
updatedM++;
updatedS = 0;
}
if (M === 60) {
updatedH++;
updatedM = 0
}
updatedMs++;
return (setTime({
ms: updatedMs,
ss: updatedS,
mm: updatedM,
hh: updatedH
}))
}
const start = () => {
setStatus(1)
run()
setInterv(setInterval(run, 10))
}
【问题讨论】:
标签: javascript reactjs react-native setinterval stopwatch