Currently, I am utilizing Vue 2 with class syntax and Typescript with TSX syntax. Despite encountering similar inquiries before, none of the proposed solutions seem to fit my specific situation.
My scenario involves creating an object array and displaying these objects as custom HTML elements, referred to as Chips
. Each Chip
has a boolean property called 'selected
'.
The array, named registerCategory
, consists of objects with a name
(essentially text) and a boolean called
is_selected</code, initialized as false by default.</p>
<p>This is how I have rendered my Array:</p>
<pre><code>{this.registerCategory.map((field, index) => (
<ZChip
position={'start'}
id = {'field-' + index}
value={field}
selected={this.registerCategory[index].is_selected}
onClick={this.onCategorySelect(index)}
>
{this.$t(this.registerCategory[index].name)}
</ZChip>
))}
The above code successfully displays all elements. However, my challenge lies in achieving selection upon click.
I have implemented a function in a separate file named registration.mixin.ts
(also where the array is defined within a computed
block):
methods: {
onCategorySelect(index: number): void {
this.registerCategory[index].is_selected = true;
},
}
The intention was for this function to alter the is_selected
as only the selected element's boolean value. Sadly, I encountered the following error:
[Vue warn]: Invalid handler for event "click": got undefined
If anyone could provide guidance, a solution, or alternative approach, it would be greatly appreciated. Thank you! :)