Dynamic css property implementation in Vue list rendering

I am currently working on creating a carousel-style list of items similar to the iOS native date/time pickers, where the list can be shifted both upwards and downwards.

The positioning of each item is determined by the `top` property from a model, which is then assigned to each individual list item element using absolute positioning.

I have successfully implemented the functionality in one direction - when you press 'go up', it behaves as intended (you can see this in the snippet below). However, when attempting to replicate the code for the opposite direction by switching the `.pop()` function with `.shift()` and `.unshift()` with `.push()`, the behavior is different. The values of the items are reassigned but nothing moves.

I observed that in the second scenario, the list items are being rendered from the beginning for some reason, disregarding the item keys. This prevents the smooth transition of coordinates.

Can anyone offer suggestions on how to make this mechanism work seamlessly in both directions? Please take a look at the provided snippet:

...

Answer №1

After analyzing the GitHub issue at github.com/vuejs/vue/issues/4834, it appears that utilizing transition-group is the solution:

The elements are not recreated, but rather moved using insertBefore. If an element with a transition is moved during the transition, the transition will be interrupted. The key ensures that the elements end up in the right position in the DOM once all manipulations are complete, although it does not guarantee they won't be moved during the process. This approach is crucial for maintaining a clear algorithm with consistent outcomes. While there may be room for improvement in the future, it is not currently considered a critical issue.

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

Is Vue compatible with SVG elements?

Is it possible to create SVG components with Vue using SVG tags? Will Vue be able to handle the correct namespace for SVG elements, or will there be limitations in this regard? ...

Retrieving POST request headers in Nightmare JS following a click() function execution and a wait() function delay

When I navigate a page, I input something in a field using type(), click on a button with click(), and then wait for an element to appear using wait(). I am interested in retrieving all the headers associated with the POST request that is triggered after ...

What is the best way to update a tag element in Vue.js?

Currently, I am working with Vuejs and struggling with a specific task - How can I replace the div tags with button tags? In the DOM, <div class="prev">prev</div> <div class="next">next</div> I would like to ac ...

Checking the loading status of .gz files in Chrome browser for a VueJs application involves a few simple steps

I currently have a VueJs application set up with webpack. In the webpack.prod.conf.js file, I have configured the productionGzip setting to generate a .gz file for each of the chunks in the dist folder. productionGzip: true, productionGzipExtensions: [&ap ...

Tips for refreshing a Vue table component following record edits?

Seeking assistance to dynamically update the vue table component with new data post editing, currently facing a challenge where the table only refreshes after a full page reload. My approach involves utilizing a sidebar window component for editing table r ...

Discovering an Uncaught TypeError: Unable to access the property 'length' of an undefined value

Looking to implement a function that checks the status of the cart and displays output accordingly. The logic is as follows: If the cart is empty (cart.line_items.length returns false), then the EmptyCart function should be executed. The "line_items" var ...

I'm looking to adjust the padding on the left and right sides of the v-select menu checkbox in Vuetify 3. How

While trying to reduce the left padding of the v-select menu checkbox using the F12 debugger, I encountered an issue where the menu suddenly disappears when clicked. This makes it difficult to see the active menu. Attached is a screenshot of the select me ...

Encountering an Ajax Issue with Laravel 5.4

I encountered the following error: "{"status":"error","msg":"Category was not created"}" Below is my Controller Function where I execute the action : function create_category(Request $request){ if($request->ajax()){ $c ...

Implementing Vue syntax highlighting in a JSP file

I've encountered an issue while using Vue in JSP files with Eclipse STS. The JSP Editor doesn't seem to support Vue syntax. Even after trying the Codemix plugin, I wasn't able to resolve the issue. It appears that Codemix only supports vue ...

Tips for Interacting with an API using curl -X Command in Vue

My dilemma is that I have stored wishlist items in a cookie, but when using an incognito tab, the cookie isn't available and the data can't be fetched. I've found a solution in the form of this extension that provides 3 endpoints: https:// ...

inject the HTML content into the <div> container

Snippet: https://jsfiddle.net/x9ghz1ko/ (Includes notes.) In my HTML file, there are two distinct sections: <section class="desktop_only"> and <section class="mobile_only">. The challenge lies in positioning a JavaScript sc ...

I am looking for a sample code for Tizen that allows scrolling of a <div> element using the bezel

Seeking a functional web application in Tizen that can scroll a div using the rotating bezel mechanism. I have dedicated several hours to getting it to work without success. I keep revisiting the same resources for the past three days: View Link 1 View Li ...

Customize Vue or Nuxt by including a highly detailed tag in the <head> section

Trying to generate static page templates using Vue/Nuxt but struggling to find a way to insert a very specific tag into the head section of each generated page. It's not a meta, script, style, or link tag, and it appears that the options in nuxt.confi ...

Concealing a button once the collapse feature is toggled in Bootstrap

The following code snippet from the bootstrap website demonstrates how to use collapse functionality: <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample"> Link with href & ...

Why is the JavaScript code not functioning when the page loads?

Here is the HTML code snippet: <head> <link href="/prop-view.css" media="screen" rel="stylesheet" type="text/css"> <script src="/javascripts/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="tex ...

Deciphering the GWT compiler's results

Although I'm not a JavaScript developer, I'm currently delving into the process of converting Java code to JS using the GWT compiler in order to identify the root cause of memory growth in our extensive application. Every now and then, I come ac ...

Discover the process of loading one controller from another controller in Angular JS

Is it possible to load an entire controller1 from a different controller2, not just a function? ...

Steps to update XmlHttpRequest URL during image upload

I am currently facing an issue with updating images on my website. When I try to update an image, it redirects to the wrong URL instead of the intended one. The form is set to post data to this URL: POST http://127.0.0.1/mgt/upload/processImage/foodImage ...

Switching on the click functionality

I was able to successfully toggle a boolean variable along with some other options. However, I encountered an issue when trying to create another click function for a different button to set the boolean variable to false. Here is my code: let manageme ...

An issue arises when attempting to integrate ajax with colorbox

I am currently facing an issue with a WordPress plugin designed for playing videos. It seems that the developer who created it is no longer available, and now the play video button has stopped working. Upon further investigation using Firebug, I noticed ...