LoginSignup
1
0

More than 3 years have passed since last update.

Vue.js の transition-group が効かない。

Last updated at Posted at 2020-05-19

注意点 1. key には繰り返す対象から直接持ってくる。

<!-- OK: key には繰り返す対象から直接持ってくる。 -->
<transition-group>
  <template v-for="element of array">
    <div :key="element.property"> {{ element.value }} </div>
  </template>
</transition-group>
<!-- NG: key には v-for の index を使わない -->
<transition-group>
  <template v-for="(element, index) of array">
    <div :key="index">{{ element.value }}</div>
  </template>
</transition-group>

注意点 2. 移動中に移動している要素のプロパティを変更しない。

値をいれると瞬間移動します。

// OK
function onClick () {
  // NG: 移動する前に変更するというのはダメでした。
  // this.array.map(element => 2* element.value)

  this.array = _.shuffle(array)

  // setTimeout で逃します。
  setTimeout(() => {
    this.array.map(element => 2* element.value)
  }, 2000)
}
// NG: 瞬間移動します。
function onClick () {
  this.array = _.shuffle(array)
  this.array.map(element => 2* element.value)
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0