[Vuejs]-Trying to pass data into computed property Vue JS

3👍

Computed properties can’t take in parameters but technically you can return a function from the computed property that takes in a parameters:

getClassesForDataItem() {
    return ui => ui ? 'border-indigo-300 ring-indigo-50' : 'border-gray-300 ring-gray-50';
}

You can also move it to a method, see here for an explanation between the two options.

1👍

Try to return a function with parameters from your computed property :

export default {
  computed: {
    getClassesForDataItem () {
      return (ui, errorClasses) => errorClasses || (ui ? 'border-indigo-300 ring-indigo-50' : 'border-gray-300 ring-gray-50')
    }
  }
}

Leave a comment