Skip to content

Instantly share code, notes, and snippets.

@mortezasabihi
Last active June 15, 2021 07:54
Show Gist options
  • Save mortezasabihi/e305b444e09e924403e24d93431b7770 to your computer and use it in GitHub Desktop.
Save mortezasabihi/e305b444e09e924403e24d93431b7770 to your computer and use it in GitHub Desktop.
Vue 3 count composition api
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