VUE3+typescript项目之setInterval的坑
## VUE3+typescript项目之setInterval的坑在做VUE3+typescrpt 项目中,使用setInteval 时的返回值报错问题。setInterval 的返回值需要定义一个变量来接收,因为typescript是强类型语言。如果直接定义接收类型是number 会报错。const state = reactive<{countDown: NodeJS.Timer |
·
## VUE3+typescript项目之setInterval的坑
在做VUE3+typescrpt 项目中,使用setInteval 时的返回值报错问题。
setInterval 的返回值需要定义一个变量来接收,因为typescript是强类型语言。如果直接定义接收类型是number 会报错。
const state = reactive<{
countDown: NodeJS.Timer | null;
[key: string]: any;
}>({
countDown: null,
});
function cancelFunc() {
visible.value = false;
context.emit('cancel');
clearInterval(Number(state.countDown));
}
附上代码自取
更多推荐
已为社区贡献1条内容
所有评论(0)