Skip to content

Instantly share code, notes, and snippets.

@guiliredu
Created June 11, 2024 23:59
Show Gist options
  • Save guiliredu/39860607cb0c3de3f4f5263ba6975eb8 to your computer and use it in GitHub Desktop.
Save guiliredu/39860607cb0c3de3f4f5263ba6975eb8 to your computer and use it in GitHub Desktop.
Vue 3 Composition API example
<template>
<div
@click="$emit('created')"
>
</div>
</template>
<script setup>
// Imports from VUE
import { onMounted, ref, defineProps, defineEmits, computed } from 'vue';
// Imports from VUE-ROUTER
import { useRouter, useRoute } from 'vue-router'
// PROPS
const props = defineProps(['total'])
// EMITS
const emit = defineEmits(['created'])
// Router
const router = useRouter();
const route = useRoute();
const id = route.params.id
const slug = route.query.slug
// Computed Property
const total = computed(() => {
return item.value.count;
});
// Reactivity State
const item = ref({
count: 0,
});
// Methods
const list = () => {
axios.get(`total`)
.then(response => {
item.value.count = response.data;
// Emits event
emit('created')
})
}
// Lifecycle Hooks
onMounted(() => {
list();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment