Skip to content

Instantly share code, notes, and snippets.

@steinbring
Created November 13, 2023 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steinbring/0b4148498d107303f49246bede78182f to your computer and use it in GitHub Desktop.
Save steinbring/0b4148498d107303f49246bede78182f to your computer and use it in GitHub Desktop.
An example of how to use a Vue composable
<template>
<div>
<router-view/>
<h1>Cocktails</h1>
<ul>
<li v-for="cocktail in cocktails" :key="cocktail.url_slug">
<router-link :to="`/${level}/${cocktail.url_slug}`">{{ cocktail.name }}</router-link>
</li>
</ul>
</div>
</template>
<script setup>
import { ref, watchEffect, defineProps } from 'vue';
import useCocktails from '../composables/useCocktails';
const props = defineProps({
level: String
});
console.log("Initial level value:", props.level);
const { cocktails } = useCocktails(props.level);
// Watch for changes and update accordingly
watchEffect(() => {
console.log("Updated level value:", props.level);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment