Tanpo
Tanpo

Reputation: 263

Nuxt and Vuetify. navigation drawer doe

I've been trying to solve this mystery for a week now.

I'm trying to set up a sidebar with Vuetify in my Nuxt/Vue website where people click on the hamburger menu and the sidebar opens up. To do this I set up the hamburger menu to run a toggle method.

<v-app-bar-nav-icon @click="toggleSidebar"></v-app-bar-nav-icon>
......
<script>
import { mapMutations } from 'vuex';
export default {
  methods: {
    ...mapMutations({
      toggleSidebar: 'appSidebar/toggleSidebar'
    })
  }
}
</script>

The method then update vuex state

export const state = () => ({
  sidebarOpen: false
})

export const mutations = {
  toggleSidebar(state) {
    state.sidebarOpen = !state.sidebarOpen;
  },
}

This works fine. The bar opens and close when I click on the hamburger menu. However, for some reason, which I'm glad it does, the sidebar closes when I click outside the sidebar (if anyone could explain how this works too i'd be appreciated). When this happens, the state doesn't update and the next time i want to open i need to click on the menu twice to get it back to close then open again.

This is how i set up the sidebar

<v-app>
  <v-navigation-drawer app temporary clipped v-model="status" color="blue lighten-3" dark>

<script>
  export default {
    computed: {
      status (){
        return this.$store.state.appSidebar.sidebarOpen   
      }
    }
  }
</script>

Thank you for your help!

Upvotes: 0

Views: 1618

Answers (1)

sanfernoronha
sanfernoronha

Reputation: 126

The drawer closes when you click outside because of the temporary prop. According to your code, your state changes only on clicking the hamburger button. But internally vuetify uses the temporary property. You can either do without your vuex code or without the temporary prop.

Upvotes: 1

Related Questions