Last active
June 15, 2021 07:54
-
-
Save mortezasabihi/e305b444e09e924403e24d93431b7770 to your computer and use it in GitHub Desktop.
Vue 3 count composition api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ref } from "vue"; | |
export default function ({ min, max, defaultValue }) { | |
const count = ref(defaultValue); | |
const increment = () => { | |
if (max) { | |
count.value < max && count.value++; | |
} else { | |
count.value++; | |
} | |
}; | |
const decrement = () => { | |
if (min) { | |
count.value > min && count.value--; | |
} else { | |
count.value--; | |
} | |
}; | |
return { | |
count, | |
increment, | |
decrement, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment