'Table body disappears when clicking first time on checkbox input

noticed a very strange behaviour from table body - it disappears on the first time when I click on checkboxes. As you will see in the gif, data is fetched successfully without any issues. I'm manipulating it whenever user tries to filter it. Couldn't find anywhere related issues to checkboxes and tables. Thanks for any ideas/advices! Want to mark that there are no errors in console, everything is clean, just inside the tbody gets empty

gif

<aside class="last-updates">
        <div>
            <span>Last 10 minutes update</span>
            <div class="checkboxes">
                <input type="checkbox" id="available" value="Available" v-model="needToFilter" @click="filterRoutes = true" />
                <label for="available">Available</label>

                <input type="checkbox" id="in-progress" value="In progress" v-model="needToFilter" @click="filterRoutes = true" />
                <label for="in-progress">In progress</label>

                <input type="checkbox" id="completed" value="Completed" v-model="needToFilter" @click="filterRoutes = true" />
                <label for="completed">Completed</label>
            </div>
        </div>

        <table class="table">
            <thead>
                <tr>
                    <th scope="col">Driver ID</th>
                    <th scope="col">Route</th>
                    <th scope="col">Latitude</th>
                    <th scope="col">Longitude</th>
                    <th scope="col">Status</th>
                </tr>
            </thead>
            <tbody v-if="routes">
                <tr v-for="route in filteredRoutes" :key="route">
                    <th>
                        {{ route.driver_id }}
                    </th>
                    <th>
                        {{ route.route_name ? route.route_name : 'No data' }}
                    </th>
                    <th>
                        {{ route.route_latitude }}
                    </th>
                    <th>
                        {{ route.route_longitude }}
                    </th>
                    <th
                        :class="
                            route.route_status === 'Available'
                                ? 'not-driving'
                                : route.route_status === 'In progress'
                                ? 'in-progress'
                                : 'completed'
                        "
                    >
                        {{ route.route_status }}
                    </th>
                </tr>
            </tbody>
            <tbody v-else>
                <p>Fetching data from database...</p>
            </tbody>
        </table>
    </aside>

<script>
import { ref, computed } from 'vue';
import getAllRoutes from '../../composables/routes/getAllRoutes';
export default {
    async setup() {
        let routes = ref([]);
        let needToFilter = ref([]);
        let filterRoutes = ref(false);

        routes = await getAllRoutes();

        const filteredRoutes = computed(() => {
            console.log(routes);
            if (filterRoutes.value) {
                if (needToFilter.value.length === 1) {
                    return routes.filter(route => route.route_status.startsWith(needToFilter.value[0]));
                } else if (needToFilter.value.length > 1) {
                    for (let i = 0; i < needToFilter.value.length; i++) {
                       // todo
                    }
                }
            } else {
                // Default sorting, displayed when page is loaded
                const sortingDefaultPriority = ['Available', 'In progress', 'Completed'];
                return routes.sort((a, b) => sortingDefaultPriority.indexOf(a.route_status) - sortingDefaultPriority.indexOf(b.route_status));
            }
        });

        return { routes, needToFilter, filteredRoutes, filterRoutes };
    }
};
</script>


Solution 1:[1]

The issue was with @click. For some reasons whenever I click the checkbox it removes the content from tbody tag. Removing the @click helped me out, found another way to watch the click.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 henrbu