26 lines
367 B
TypeScript
26 lines
367 B
TypeScript
export const useCounter = () => {
|
|
const count = ref(0);
|
|
|
|
const increment = () => {
|
|
count.value++;
|
|
};
|
|
|
|
const decrement = () => {
|
|
count.value--;
|
|
};
|
|
|
|
const reset = () => {
|
|
count.value = 0;
|
|
};
|
|
|
|
const double = computed(() => count.value * 2);
|
|
|
|
return {
|
|
count: readonly(count),
|
|
increment,
|
|
decrement,
|
|
reset,
|
|
double,
|
|
};
|
|
};
|