category chooser emits id

practiced-songs
Matthew Huntington 1 year ago
parent 9cebd803e6
commit 37378a67ac

@ -1,5 +1,6 @@
<script setup> <script setup>
import { onMounted, ref, watch } from 'vue' import { onMounted, ref, watch, } from 'vue'
const emit = defineEmits(['update'])
const props = defineProps(['categories']) const props = defineProps(['categories'])
const instruments = ref([]) const instruments = ref([])
const chosenInstrument = ref('clarinet') const chosenInstrument = ref('clarinet')
@ -8,6 +9,9 @@
instruments.value.push(category.instrument) instruments.value.push(category.instrument)
} }
} }
const handleSelection = (event)=>{
emit('update', event.target.value)
}
</script> </script>
<template> <template>
<h3>Choose Category</h3> <h3>Choose Category</h3>
@ -16,8 +20,8 @@
{{instrument}} {{instrument}}
</option> </option>
</select> </select>
<select v-for="instrument in instruments" :key="instrument" v-show="instrument == chosenInstrument"> <select @change="handleSelection" v-for="instrument in instruments" :key="instrument" v-show="instrument == chosenInstrument">
<option v-for="category in props.categories" :key="category.id" v-show="category.instrument == instrument" :selected="category.instrument == instrument"> <option v-bind:value="category.id" v-for="category in props.categories" :key="category.id" v-show="category.instrument == instrument" :selected="category.instrument == instrument">
{{category.category}} {{category.category}}
</option> </option>
</select> </select>

@ -45,7 +45,7 @@
{{category.category}} {{category.category}}
</option> </option>
</select> </select>
<CategoryChooser v-if="categories.length > 0" :categories="categories" /> <CategoryChooser @update="loadCategory" v-if="categories.length > 0" :categories="categories" />
<table> <table>
<thead> <thead>
<tr> <tr>

Loading…
Cancel
Save