Vue3 倒计时效果 - 格式处理(分 - 秒)
下载dayjs
yarn add dayjs
or
npm i dayjs
import {
useIntersectionObserver } from '@vueuse/core'
import {
ref } from 'vue'
import dayjs from 'dayjs'
// 🔔 作业:倒计时效果
export const usePayTime = () => {
const time = ref(0)
const timeText = ref('')
const {
resume, pause } = useIntervalFn(() => {
time.value--
// 格式化后中文时间
timeText.value = dayjs.unix(time.value).format('mm分ss秒')
if (time.value <= 0) {
pause()
}
}, 1000, {
immediate: false })
const start = (number) => {
time.value = number
// 格式化后中文时间
timeText.value = dayjs.unix(time.value).format('mm分ss秒')
resume()