A
A
annaelinevich2020-12-12 16:46:48
JavaScript
annaelinevich, 2020-12-12 16:46:48

How to link a menu toggle to a toggle switch?

The menu is switched by pressing the NOT and ATCHETECTURE buttons, as well as by pressing the toggle switch, but for some reason the toggle switch does not work as it should (when you click on it, switchOn does not change from true to false and, accordingly, the menu does not switch). What could be wrong?

<template>
    <div class="nav-menu">
           <div
           v-for="(title, index) in ['not', 'archetecture']"
            :class="['accordion__title', {'active': index == activeIndex}]"
           :key="`${title}_${title}`"
           @click="getCategoriesTitle(title, index)">{{title}}
            <div v-if="index % 2 === 0" class="switch-btn-wrapper"
            @click="getCategoriesTitle(switchOn ? 'archetecture' : 'not')"
               >
                <div class="switch-btn" :class="{'switch-on': switchOn}"
                >
        </div> 
    </div>    
 </div>
                   
        <div class="accordion" 
        v-for="(item, index) in NAV_TITLES"
        :key="`${item}_${index}`">
            <ul>
              <div class="accordion__submenu submenu">
            <li 
                :class="['submenu submenu__item', {'active': index === activeItem}]"
                @click="getCategoriesItem(item, index)"
                >{{item}}         
                </li>          
              </div>
            </ul>
           
        </div>
</div>
</template>

<script>
import { mapGetters, mapMutations } from 'vuex';
export default {
    name: 'NavMenu',
    data: () => ({
        activeIndex: 1,
        activeItem: null,
        isActive: false,
        switchOn: true,
    }),
    computed: {
    ...mapGetters(['NAV_LINKS', 'NAV_TITLES']),
    },
    methods: {
          ...mapMutations(['CHANGE_CURRENT_MENU', 'CHANGE_CURRENT_TITLE']),

        getCategoriesTitle(title, index) {
            this.CHANGE_CURRENT_TITLE(title)
               this.switchOn = !this.switchOn
            this.activeIndex = this.activeIndex === index ? this.activeIndex : index
        },
        getCategoriesItem(navItem, index) {
            this.CHANGE_CURRENT_MENU(navItem)
            this.activeItem = this.activeItem === index ? this.activeItem : index
        },
    }
}
</script>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question