H
H
HamSter2018-11-02 16:04:38
Vue.js
HamSter, 2018-11-02 16:04:38

Vue lodash.shuffle for a list?

Codesandbox ShuffleList.vue
There is a list with animation lodash.shuffle:

<template>
  <div id="filter">
    <button v-on:click="shuffle">Перемешать</button>

    <transition-group 
      name="list" 
      mode="out-in" 
      tag="ul" 
      class="catalog-list">

      <li 
        :key="index" 
        v-for="(item, index) in items">

        <h3>{{ item.name }}</h3>
        <span>{{ item.price }}</span>

      </li>

    </transition-group>

  </div>
</template>

<script>
import _shuffle from "lodash.shuffle";

export default {
  name: "FilterList",
  data() {
    return {
      items: [
        { name: "Name 1", price: "200" },
        { name: "Name 2", price: "100" },
        { name: "Name 3", price: "5" }
      ]
    };
  },
  methods: {
    shuffle() {
      this.items = _shuffle(this.items);
    }
  }
};
</script>

I do the example, but the animation does not happen.
Question: How to implement lodash.shuffle animation for a list?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-11-02
@HamSter007

You should never use an index as a key. So that this, as you have now, was not.
We make a normal key - everything is okay .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question