I'm working on a Nativescript-Vue app, and I'm trying to use Vuex to store the hour and minute from a Timepicker to use in other Pages. I've tried catching the event with a computed property, but is there a better way of doing this with Vue?
Here's what I have:
// In NotifyTimePicker.vue (a custom Time-picking modal)
// Template:
<TimePicker row="2" col="0" colSpan="3" horizontalAlignment="center" :hour="selectedFromHour" :minute="selectedFromMinute" />
//Script
computed: {
selectedFromHour: {
get: function () {
return this.$store.state.notifyFromTimeHour
},
set: function (newValue) {
console.log(`Attempting to Update Store with new From Hour = ${newValue}`)
this.$store.commit('changeNotifyFromTimeHour', newValue)
}
},
selectedFromMinute: {
get: function () {
return this.$store.state.notifyFromTimeMinute
},
set: function (newValue) {
console.log(`Attempting to Update Store with new From Minute = ${newValue}`)
this.$store.commit('changeNotifyFromTimeMinute', newValue)
}
},
},
Then, in my Vuex store:
export default new Vuex.Store({
state: {
notifyFromTimeHour: 9,
notifyFromTimeMinute: 30,
},
mutations: {
changeNotifyFromTimeHour (state, hour) {
state.notifyFromTimeHour = hour
},
changeNotifyFromTimeMinute (state, minute) {
state.notifyFromTimeMinute = minute
},
},
actions: {
}
});
It appears that the default values from the Store get pulled into the component just fine, but when changing the time in the picker, the 'set' part of the computed function never fires, and I never see my console.logs firing.
Should I be listening to a different change event? The documentation here doesn't go into detail on this much.
Thanks for the help!