[Vuejs]-Toggle boolean data/prop value of li element

0👍

Here is how I solved this:

<li
    v-for="(subNavItem, index) in navItem.children"
    :key="index"
    @click="toggle(subNavItem, navItem)"
>

methods: {
    toggle(subNavItem, navItem) {
        // uncheck all languages
        navItem.children.map(function(x) {
            x.isSelected = false;
        })
        // check language
        this.$set(subNavItem, 'isSelected', !subNavItem.isSelected)
        this.$forceUpdate();
    }
}

Leave a comment