Obtaining all available categories:
const fetchCategories = async () => {
let response = await axios.get(`/api/get_all_category/`)
categories.value = response.data.categories
}
The structure of categories.value is shown here:
https://i.sstatic.net/IIXai.png
Initializing the default option:
let selectedCategory
const fetchSingleProduct = async () => {
let response = await axios.get(`/api/get_edit_product/${props.id}`)
form.value = response.data.product
//form.value.category_id ranges from 1 to 6
selectedCategory = ref(form.value.category_id)
}
Constructing the select dropdown menu:
<div class="my-3">
<p>Select product type</p>
<select v-model="selectedCategory">
<option v-for="category in categories" :key="category.id" :value="category.id">
{{ category.name }}
</option>
</select>
</div>
All options are displayed correctly, but the default selection does not seem to be applied as expected.