Skip to content

Instantly share code, notes, and snippets.

@steinbring
Created November 13, 2023 02:56
Show Gist options
  • Save steinbring/7337e0cf7446eaed9d3e12020dc1e3c7 to your computer and use it in GitHub Desktop.
Save steinbring/7337e0cf7446eaed9d3e12020dc1e3c7 to your computer and use it in GitHub Desktop.
An example of a Vue composable
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