Created
November 13, 2023 02:56
-
-
Save steinbring/7337e0cf7446eaed9d3e12020dc1e3c7 to your computer and use it in GitHub Desktop.
An example of 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
import { ref, onMounted } from 'vue'; | |
import simpleCocktails from '../data/simple_cocktails.json'; | |
import intermediateCocktails from '../data/intermediate_cocktails.json'; | |
import advancedCocktails from '../data/advanced_cocktails.json'; | |
export default function useCocktails(level) { | |
const cocktails = ref([]); | |
onMounted(() => { | |
switch(level) { | |
case 'simple': | |
cocktails.value = simpleCocktails; | |
break; | |
case 'intermediate': | |
cocktails.value = intermediateCocktails; | |
break; | |
case 'advanced': | |
cocktails.value = advancedCocktails; | |
break; | |
default: | |
cocktails.value = []; | |
} | |
}); | |
return { cocktails }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment