i am using vue3 with options api
as shown in the section titled code
, i set an object to a store
. in section storeTest.vue
it shows how the store
is implemented, and in watch
it shows how i listen to changes occured to the store
.
at run time, despite there are values assigned to either of geojson
and order
, the watch
statement does not report any changes occured. i expect that the values assigned to geojson
and order
are to be printed in the console,
but nothing gets displayed
why that is happening and how to solve it
code:
StoreTest.setters.set({
geojson: this.#featureRecentlyRequestedProcessing.value.get(DigitizePolygonConstants.CONST_DIGITIZED_FEATURE_PROPERTY_GEOJSON.description),
order: this.#featureRecentlyRequestedProcessing.value.get(DigitizePolygonConstants.CONST_DIGITIZED_FEATURE_PROPERTY_GEOM_ORDER.description),
});
storeTest.vue:
<script>
import { reactive } from 'vue';
export default {
}
export const StoreTest = ({
state: reactive({
array: [],
}),
getters: {
get() {
return StoreTest.state.array;
},
},
setters: {
set(obj) {
StoreTest.state.array.push(obj);
},
},
actions: {
initialize() {
StoreTest.state.array = [];
},
}
});
</script>
watch:
created() {
console.log(verboseTag, 'created()');
this.$watch(this.refStoreTest.getters.get, (newVal, oldVal) => {
msg = JSON.stringify({msg: verboseTag + '@watch refStoreTest.getters.get()', newVal: newVal, oldVal: oldVal});
console.log(msg);
newVal = newVal.sort((a,b) => a.order-b.order);
this.refStroeRecentlyHoveredGeometriesProps.setters.set(newVal);
});
}
1