[Vuejs]-Is it possible to pass an argument to a computed property that is used for class and style bindings?

3๐Ÿ‘

โœ…

If you need arguments then you want to write a method, not a computed property.

<button :class="styleMinusButton(i)">...</button>
methods: {
  styleMinusButton(i) {
    const { travelers, curOcc, minOcc } = this
    return {
      'uk-disabled uk-button-default': travelers[i] == 0 || (curOcc !== 1 && curOcc <= minOcc),
      'uk-button-primary': travelers[i] > 0 && (curOcc > minOcc || curOcc >= minOcc && travelers[i] === 1 && travelers[i+1] !== 1 && travelers[i+2] !== 1 && travelers[i-1] !== 1 && travelers[i-2] !== 1)
    }
  }
}
๐Ÿ‘คDecade Moon

Leave a comment