How vue does list rendering

now there is a need for animated list rendering.
but I found a problem in the process of writing, and I don"t know how to solve it

the existing parent component constantly fetches the value passed by the server through socket, puts it into an array, and then passes the array to the child component

          socket.onmessage = (event) => {
            const socketData = JSON.parse(event.data)
            if (socketData.type === "wz") {
              this.wzSocket = socketData.data
            } else if (socketData.type === "warn") {
              this.warningSocket.unshift(socketData.data)
            }
          }
the unshift used here always wants the first value to enter the array to have a dynamic effect.
The

subcomponent transitions the list of passed arrays, but finds that if key fills in the object item, the background will report an error, key duplicates, and object cannot be used as a key, recommendation to use string or number.
so this side is changed to index.

      <transition-group name="list" tag="span">
        <div v-for="(item,index) in warningData" :key="index" class="list-item">
          {{item.recordtime}} +{{index}}
          <el-button type="text" size="mini" @click="handleClickDetails(item)"></el-button>
        </div>
      </transition-group>

existing effect:

After
is rendered, if the key is filled with item objects, then the animation will always appear first in the list, but if you fill in index, the animation will appear in turn. If you use the method to generate key dynamically. Then all will be animated.

so, how can we always make the first element of an array have a dynamic effect

?
Mar.23,2021

or order your own id , and increment it.

is it like this?

https://jsfiddle.net/wdqy52bk.


in this case, take a closer look at the document ide/list.html-sharpkey" rel=" nofollow noreferrer "> key . In the Vue list, key is used to identify which of each rendered element is which. In JS Object, you cannot use an object as a key name, so you will report an error when you use object. But if you use index as key, then each unshift new element naturally affects the index of all elements, so it's normal to restart the animation all over.

should use id or generate an id for key yourself.


your question is: how can you always make the first element of an array dynamic?

you can try to be the first to take out the array and put it in < transition > < / transition >
, and then put other data into the normal div to render in a loop

.

< transition-group > < / transition-group > is list rendering

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3f328-409ff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3f328-409ff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?