0

I am trying to create a computed property where it checks item is in the array. So i created this function that returns boolean value and takes one parameter which is the item i will check.

isSelected: function (item: MediaGalleryItemTypes) {
  return this.selectedItems.some(e => e._id === item._id)
}

In the template section i have to send the variable to another component, here is how i use it

 DocumentCard(:is-selected="isSelected(document)")

The code gives error as

chunk-common.js:5918 Uncaught (in promise) TypeError: _ctx.isSelected is not a function

and in vscode it gives the error as:

This expression is not callable. Type 'Boolean' has no call signatures.

How can i fix this and make a computed property to get a parameter?

  • There's not enough context to reproduce the problem. Can you show the full component definition for that method and template? – tony19 Jun 14 '22 at 22:18
  • The quick answer to your question is: by making the computed return a function. But chances are there's a simpler way: using a regular function (a.k.a. Options API method) instead of a computed. Why don't you show us the relevant code of your component? Are you using Options/Composition API? How does the relevant bit of ` – tao Jun 14 '22 at 23:03

1 Answers1

1

You can't pass parameters to computed properties (unless the computed return a function). You can use with the standard method

Can I pass parameters in computed properties in Vue.Js

RBT
  • 24,161
  • 21
  • 159
  • 240
meir
  • 46
  • 3