LoginSignup
9
3

More than 3 years have passed since last update.

sortをいれるとUnexpected side effect in computed propertyってエラー

Posted at

Vue.jsで
Unexpected side effect in "xxx" computed property
というエラーがでたのでメモ

computedで配列をsortして返そうとしたらエラー

computed: {
  members() {
    return this.xxx.sort((a, b) => {
      if (a < b) return -1
      if (a > b) return 1
      return 0
    })
  }
}

computed: {
  members() {
    return this.xxx.slice().sort((a, b) => {
      if (a < b) return -1
      if (a > b) return 1
      return 0
    })
  }
}

これでエラー回避できた。

9
3
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
9
3