Created
November 13, 2023 03:08
-
-
Save steinbring/0b4148498d107303f49246bede78182f to your computer and use it in GitHub Desktop.
An example of how to use a Vue composable
This file contains hidden or 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
<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