Animating table rows in Vue 3

Struggling to implement a transition (animation) on an HTML table, that works fine for a list but not for a table. The transition is functional when using vue 2.

Tweaked my code based on this fiddle.

This represents the HTML:

<div id="app">
    <div class="row p-2">
        <div class="col-6">
            <h2>List</h2>
            <transition-group class="list-group" name="fruit-list" tag="ul">
                <li class="list-group-item" v-for="item in items" :key="item.id">
                    <div class="d-flex align-items-center">
                        <div>
                            {{ item.name }}
                        </div>
                    </div>
                </li>
            </transition-group>
        </div>
        <div class="col-6">
            <h2>Table</h2>
            <table class="table mb-0">
                <thead>
                <tr>
                    <th scope="col">Fruit</th>
                </tr>
                </thead>
                <tbody name="fruit-table" is="transition-group">
                <tr v-for="item in items" :key="item.id">
                    <th scope="row">{{ item.name }}</th>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

This demonstrates the CSS:

<style>
    .fruit-list-move {
        transition: transform 1s;
    }
    .fruit-table-move {
        transition: transform 1s;
    }
</style>

Here's the javascript:

   <script>
        const myapp = {
            data() {
                return {
                    items: [
                        {
                            id: 1,
                            name: "Bananas",
                            quantity: 5
                        }, {
                            id: 2,
                            name: "Apples",
                            quantity: 3
                        }, {
                            id: 4,
                            name: "Oranges",
                            quantity: 1
                        }, {
                            id: 5,
                            name: "Stawberries",
                            quantity: 25
                        },
                    ]
                }
            },

            mounted() {
                this.addItem()
            },

            methods: {
                addItem() {
                    this.items.splice(2, 0, {
                        id: 3,
                        name: "Kiwis",
                        quantity: 8
                    })
                    setTimeout(() => {
                        this.moveItems()
                    }, 2000)
                },
                moveItems() {
                    this.items = this.items.reverse()
                    setTimeout(() => {
                        this.removeItem()
                    }, 2000)
                },
                removeItem() {
                    this.items.splice(2, 1)
                    setTimeout(() => {
                        this.addItem()
                    }, 2000)
                }
            }
        }
        app = Vue.createApp(myapp)
        app.mount('#app')
    </script>

I'm slightly confused about the readiness of Vue 3 as well. The homepage still primarily focuses on Vue 2.

Answer №1

Discover the solution to your animation troubles...

<tbody tag="tbody" name="list" is="transition-group">
  <tr v-for="..." :key="...">...</tr>
<tbody>

Check out this helpful example in Pug on CodePen.

Your table's animation issues may be due to the positioning of tr within tbody, causing browser tree reassembly complications...

To resolve this, consider transforming tbody into transition-group, with some Vue 3 updates impacting the process.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on interpreting a JavaScript page prior to another

function moveCharacter() { ctx.clearRect(0, 0, canvas.width, canvas.height) let position = Math.floor(gameFrame/staggerFrame) % spriteAnimation[playerState].loc.length let frameX = spriteWidth * position let frameY = spriteAnimation[player ...

What is the best way to transfer an item from one object to another within the same array using javascript?

I'm dealing with an array structure like the following: [ { "ID": 227886, "post_author": "54" }, { "ID": 227545, "post_author": &q ...

Convert a nested array of objects to an array containing only objects

I have a unique challenge with an array of nested objects. How can I create a new array of objects by extracting values from nested properties? In cases where the onClick property is empty, I need to look for a children property and exclude the parent elem ...

Difficulty Converting Array of Objects to Proper Type with Q.Promise and KO.mapping

I have encountered an issue while trying to filter an observable array. It seems that the ko.utils.arrayFilter method is converting all my model's field names to lowercase, causing unexpected behavior. I should mention that this project involves Types ...

The mystery behind the enigmatic combination of ajax, JQuery,

Seeking Assistance! All fields are displaying undefined values function UpdateData(){ var id = $('#id').attr('value'); var name = $('#name').attr('value'); var department = $('#departament'). ...

Leveraging the power of LocalStorage in Ionic 2

Trying to collect data from two text fields and store it using LocalStorage has proven tricky. Below is the code I have set up, but unfortunately it's not functioning as expected. Can you provide guidance on how to resolve this issue? In page1.html ...

The Bootstrap modal causes the scrollbar to vanish upon closure

Despite trying numerous solutions and hacks on this issue from StackOverflow, none of them seem to work for me. Currently, I am utilizing a modal for the login process in Meteor (e.g. using Facebook login service) which triggers a callback upon successful ...

Is npm installation specifically for a node server?

I'm in the process of developing a React app with webpack and utilizing npm to install different front end packages such as tabs, D3, and more. As I plan for production, I'm wondering if I specifically need to run my server as a Node server given ...

Opting out of accents in the Vue filter and utilizing the table filter feature provided by Bootstrap-Vue

I am currently utilizing the Bootstrap-vue Table for filtering purposes, and I require assistance in implementing a regex filter to exclude words or letters with accents. Here is the regex snippet: string.replace('/[áàãâä]/ui', 'a&apos ...

Exploring a Ring with Three.js OrbitControls Rotation

I am having an issue with my OrbitControls camera setup. Currently, the camera rotates around a fixed point at player.position.x, y, and z coordinates. While it works fine, I need the camera to rotate around a ring instead. In the examples provided, the fi ...

Strategies for Creating a Test Suite for RepositoryFactory in Vue.js/Nuxt.js

Summary of RepositoryFactory Implementation An implementation of the RepositoryFactory pattern has been carried out for API connection in a Vue.js/Nuxt.js application. For more details, refer to this article: here hogeRepository.ts import { NuxtAxiosInst ...

Can CSS be used to communicate to JavaScript which media queries are currently in effect?

Is there a way for Javascript to detect when a specific CSS media query is active without repeating the conditions of the media query in Javascript? Perhaps something similar to an HTML data attribute, but for CSS. For example: CSS @media (min-width: 94 ...

Issues arise when using PHP4 in conjunction with Ajax, the json_encode function, and

I have been tasked with a project for my company that requires PHP4 development. The goal is to display a list of mobile phone brands and their prices, as well as the ability to filter them using multiple checkboxes. However, I am facing an issue where the ...

What is the method for showing the arrays following Json.stringify and Json.parse?

I've been facing challenges trying to redirect notifications from my mobile application to another page and store them as historical records. Despite my efforts in researching and experimenting with various methods, I have yet to achieve the desired o ...

Having trouble with Electron nodeIntegration functionality and experiencing some odd behavior in general with Electron

Having just started working with Electron, I find myself encountering some puzzling behavior that has me stumped. Here's a quick summary of the issue: I am unable to establish communication between Electron and the HTML "Uncaught ReferenceError ...

Utilizing AJAX for dynamic form input fields and auto-complete functionality

I've successfully implemented a code that allows me to dynamically add input fields with AJAX for auto-completion. However, there are some limitations. As shown in this image: https://i.sstatic.net/wQKWv.png The auto-fill results are not appearing be ...

Capture a fragment of a scene and convert it into a unique texture using THREE.JS

I'm interested in creating a texture of a specific area in my scene, similar to the example shown in the official documentation for three.js framebuffer here. As I examine the code provided, there's one particular aspect that's unclear to me ...

Implement ajax functionality to update an object within a JSP page

On my JSP page, I have implemented an accordion list (utilizing Bootstrap 3) with text and a Delete button within each node. When the user clicks on the delete button, that specific list item is removed. To construct the accordion list, I bring in an Array ...

The StateProvider is giving back an iteration that is undefined

AppContext.js import React, { createContext, useContext, useReducer } from "react"; // Initialize the appContext export const AppContext = createContext(); // Wrap the app and set up the App Context export const AppProvider = ({ reducer, initia ...

Changing data in vue

I am utilizing a mixin in my Vue code to both add and override data properties. While I can successfully add new data, I am facing issues when trying to override existing data values. Below is a snippet of the code: var mixin = { data: function() { ...