I am working on a music app. On logout the music still keeps playing. So I tried using Vuex to have a global boolean state of: logged (in or out)... and by that - try to catch the updated state. If the state is loggedOut - the music stops playing. The music is being played from another component - MusicPlayer.vue. My question: When i am trying to watch for a state change, the change does not get caught, therefore the music still keeps playing. What am I doing wrong?
computed: {
loggetOUT () {
return this.$store.login.getters.loggetState
}
},
watch: {
loggedOUT (value) {
console.log(value)
if (value) {
sound.pause()
sound = null
}
}
}
store/login.js:
export const state = () => ({
logged: false
})
export const mutations = {
LOGGED_IN (state) {
state.logged = true
},
LOGGED_OUT (state) {
state.logged = false
}
}
export const getters = {
loggedState (state) {
return state.logged
}
}
I set the state to false on logout in my default template:
logout (store) {
this.$auth.logout()
this.$store.commit('login/LOGGED_OUT')
}