老师,我遇到个bug,留的删除作业10s自动退出感觉有点问题,停在9s
App.vue新增代码如下:
<script setup>
import MyDelete from "./components/delete.vue";
const MydeleteShow = ref(false);
const indexOfTodo = ref();
const deleteTodo = function (index) {
console.log("deleteTodo");
indexOfTodo.value = index;
MydeleteShow.value = true;
};
const deleteTodoConfirm = function (index) {
MydeleteShow.value = false;
list.value[index].del = true;
};
const deleteTodoCancel = function () {
MydeleteShow.value = false;
};
</script>
<template>
<MyDelete
:isShow="MydeleteShow"
@del="deleteTodoConfirm"
@cancel="deleteTodoCancel"
:index="indexOfTodo"
/>
</template>
delete.vue的主要代码如下:
<script setup>
import { defineProps, defineEmits, ref, watch } from "vue";
const props = defineProps({
isShow: Boolean,
index: Number,
});
const isShow = ref(props.isShow);
const count = ref(10);
const updateCount = function () {
count.value--;
if (count.value === 0) {
clearInterval(timer);
cancel();
}
};
let timer = setInterval(updateCount, 1000);
watch(
() => props.isShow,
(value) => {
isShow.value = value;
if (isShow.value === true) {
count.value = 10;
updateCount();
}
},
);
const indexOfTodo = ref();
watch(
() => props.index,
(value) => {
indexOfTodo.value = value;
},
);
const emits = defineEmits(["del", "cancel"]);
const del = function () {
isShow.value = false;
emits("del", indexOfTodo.value);
};
const cancel = function () {
isShow.value = false;
emits("cancel");
};
</script>
<template>
<div v-if="isShow" class="masking"></div>
<div v-if="isShow" class="popover">
<div class="popover-con">
<div class="popover-info">
<div class="content">
<p>警告({{ count }}秒后自动取消)</p>
<p>是否要删除当前选项?</p>
</div>
<div class="operateBar">
<button @click="cancel">取消</button>
<button @click="del">确认</button>
</div>
</div>
</div>
</div>
</template>