I want to add the class menu-opened
on the body
tag when I click on the menu burger div.
My div
<div v-on:click="openMenu"></div>
The openMenu method
methods: {
openMenu() {
console.log('open menu launch')
this.$store.dispatch('menu/setMenu', true)
}
}
My store
state = {
isMenuOpen: false
}
actions = {
setMenu({ commit }, value) {
commit('SET_MENU_OPEN_STATUS', value)
}
}
mutations= {
SET_MENU_OPEN_STATUS(state, newState){
state.isMenuOpen = newState
}
}
On my template, i got this code to add the class on the body based on the state of the isMenuOpen value :
export default {
data() {
return {
menuState: this.$store.state.isMenuOpen
}
},
head () {
return {
bodyAttrs: {
class: this.menuState ? 'menu-opened' : ''
}
}
}
}
My store is working well, the value change when I click on my div, but it's not adding the class, like if the head function is not reactive...
Thanks for your help
<body>
? – Jase