鼬鼬鼬鼬鼬被提需求了!!!
产品:你学什么的?
我:跟CV有点关系
产品:control C加control V是吧
我:对对对
效果
时间实时变化:
页面部分
<template>
<div class="dateBox">
<div class="time">{{ time }}</div>
</div>
</template>
ts部分
<script lang="ts" setup>
import { ref, onMounted ,onUnmounted} from 'vue'
const time = ref(null)
onMounted(() => {
const clock = setInterval(() => {
time.value = getToday().time;
}, 1000);
// 使用onUnmounted清除定时器
onUnmounted(() => {
clearInterval(clock);
});
})
// 时间格式化:获取当前时间,格式化为15:35:06
function getToday() {
var datas = new Date();
var on1 = " / ";
var on2 = " : ";
var onS = datas.getHours(); //时
var onF = datas.getMinutes(); //分
var onN = datas.getSeconds(); //秒
if (onS >= 0 && onS <= 9) {
//时
onS = "0" + onS;
}
if (onF >= 0 && onF <= 9) {
//分
onF = "0" + onF;
}
if (onN >= 0 && onN <= 9) {
//秒
onN = "0" + onN;
}
return {
time: onS + on2 + onF + on2 + onN,
};
}
</script>
样式
<style lang="less" scoped>
.dateBox {
background: #121747;
background-repeat: no-repeat;
display: flex;
align-items: flex-end;
justify-content: flex-end;
position: absolute;
margin-left: 20%;
}
.time {
font-size: 20px;
color: #ffffff;
}
</style>