I set up an API with Laravel 10. The data comes fine with postman
GET:http://localhost:8000/api/countries
{
"data": [
{
"id": 1,
"country_code": "AF",
"country_name": "Afghanistan",
"status": 1
},
{
"id": 2,
"country_code": "AL",
"country_name": "Albania",
"status": 1
},
in my script tag i'm getting the data in the console i see the array if data.
<script>
import { reactive, onMounted } from 'vue';
import axios from 'axios';
export default {
name: 'SignupPage',
setup() {
// Form data
const formData = reactive({
country: null,
});
// List of countries
const countries = reactive({ data: [] });
// Fetch countries from API
onMounted(() => {
axios.get('http://localhost:8000/api/countries')
.then(response => {
countries.value = response.data.data;
console.log('Countries:', countries.value);
})
.catch(error => {
console.error('Error fetching countries:', error);
});
});
// Method to submit form
const submitForm = () => {
// Logic to submit form data to API
console.log(formData.value);
};
return {
ageOptions,
countries,
};
},
};
</script>
everything seem to store it self in countries which i use in the Vue/ionic code
<ion-col size="12" class="ion-margin-bottom">
<ion-label>Country</ion-label>
<ion-select v-model="formData.country">
<ion-select-option v-for="country in countries.data"
:value="country.id" :key="country.id">
{{ country.country_name }}
</ion-select-option>
</ion-select>
</ion-col>
i have tried tons of different combinations and even Vue tag instead of Ionic but the dropdown remains empty....
what am i missing??
the other dropdowns work fine with local values like
<ion-col size="6" class="ion-margin-bottom">
<ion-label>Max Age</ion-label>
<ion-select v-model="formData.maxAge">
<ion-select-option v-for="age in ageOptions" :value="age" :key="age">
{{ age }}</ion-select-option>
</ion-select>
</ion-col>
// List of age options
const ageOptions = [];
for (let age = 18; age <= 100; age++) {
ageOptions.push(age);
}