@@ -55,6 +55,7 @@ const modelValue = defineModel<string | number | null>('modelValue', {
55
55
// Reactive states
56
56
const options = ref <Place []>([])
57
57
const loading = ref (false )
58
+ const initialized = ref (false )
58
59
const selectedValue = ref <string | number | null >(null )
59
60
60
61
// Local reactive copy of params to avoid mutating the prop directly
@@ -116,7 +117,11 @@ const fetchPlaces = async () => {
116
117
emitChange (selectedValue .value )
117
118
} else {
118
119
selectedValue .value = modelValue .value
120
+ if (! initialized .value ) {
121
+ emitChange (selectedValue .value )
122
+ }
119
123
}
124
+
120
125
doneBus .emit ({ key: props .type , value: selected .value ?.iso2 ?? selectedValue .value ! }) // Indicate data is ready
121
126
} catch (error ) {
122
127
emit (' error' , ' Error fetching places:' , error )
@@ -126,6 +131,7 @@ const fetchPlaces = async () => {
126
131
127
132
// Emit value changes to parent and event bus
128
133
const emitChange = (value : string | number | null ) => {
134
+ initialized .value = true
129
135
if (value !== null ) {
130
136
modelValue .value = value
131
137
bus .emit ({ key: props .type , value: selected .value ?.iso2 ?? value })
@@ -141,6 +147,7 @@ const onChange = () => {
141
147
// eslint-disable-next-line @typescript-eslint/no-explicit-any
142
148
const onUpdateModelValue = (value : any ) => {
143
149
selectedValue .value = value
150
+ modelValue .value = value
144
151
emitChange (value )
145
152
}
146
153
@@ -162,6 +169,8 @@ doneBus.on(({ key, value }) => {
162
169
163
170
// Fetch data on mount
164
171
onMounted (async () => {
165
- await fetchPlaces ()
172
+ if (Object .values (localParams .value ).length <= 0 ) {
173
+ await fetchPlaces ()
174
+ }
166
175
})
167
176
</script >
0 commit comments