简体   繁体   中英

Error in nextTick: “TypeError: Cannot read property 'key' of undefined” in vue

I used same approach as here to make something similar but when ever I click on buttons sometimes it happens right away sometimes after 20 clicks....

Here is my code: (Inside .vue file)

<template>
<div class="right-bar" :class="{'hide':!open}">
    <div class="header-bar">
        <button @click="changeTab(1)" class="hbm" :class="[ activetab === 1 ? 'active' : '' ]">
            <i class="fas fa-tachometer-alt"></i>
        </button>
        <button @click="changeTab(2)" class="hbm" :class="[ activetab === 2 ? 'active' : '' ]">
            <i class="fas fa-comments"></i>
        </button>
        <button @click="changeTab(3)" class="hbm" :class="[ activetab === 3 ? 'active' : '' ]">
            <i class="fas fa-bell"></i>
        </button>
        <button @click="changeTab(4)" class="hbm" :class="[ activetab === 4 ? 'active' : '' ]">
            <i class="fas fa-cog"></i>
        </button>
        <i class="fas rs-btn" :class="[open?'fa-chevron-down':'fa-chevron-up']" @click.prevent="open=!open"></i>
    </div>
    <div class="content-form">
        <div class="form" v-if="activetab === 1">
            <slot name="overview"></slot>
        </div>
        <div class="form" v-if="activetab === 2">
            <slot name="messages"></slot>
        </div>
        <div class="form" v-if="activetab === 3">
            <slot name="notifications"></slot>
        </div>
        <div class="form" v-if="activetab === 4">
            <slot name="settings"></slot>
        </div>
    </div>
</div>
</template>

<script>
    export default {
        data() {
            return {
                open: true,
                activetab: 1
            }
        },
        methods: {
            changeTab(i) {
                this.activetab = i;
            }
        }
    };
</script>

Here is a quick video of it: (because as I said some times it happens in few some times in lot clicks)

https://streamable.com/zpk4m

Both versions are 2.5.17 but I use one with laravel fresh installation.. Also I have installed vuex and lodash... if it means something

Answer in my case was duplication of elements:

My tab element is:

<div class="form" v-if="activetab === 2">
     <slot name="messages"></slot>
</div>

and for slot I used:

<div class="form" slot="messages">

</div>

I duplicated same element and caused which caused crashing :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM