import { ref, onMounted, onUnmounted } from 'vue'; export default function useTimeDiff(targetDateStr) { const days = ref(0); const hours = ref(0); const minutes = ref(0); const calculateDiff = () => { const targetDate = new Date(targetDateStr.replace(/-/g, '/')); const now = new Date(); const diffMs = now - targetDate; days.value = Math.max(0, Math.floor(diffMs / 86400000)); hours.value = Math.max(0, Math.floor((diffMs % 86400000) / 3600000)); minutes.value = Math.max(0, Math.floor((diffMs % 3600000) / 60000)); }; let timer; onMounted(() => { calculateDiff(); timer = setInterval(calculateDiff, 60000); }); onUnmounted(() => { clearInterval(timer); }); return { days, hours, minutes }; }