As someone who is still getting the hang of VueJS, I've come across a challenge that would have been a breeze to tackle with jQuery. However, when it comes to VueJS, I'm struggling to find a solution even though I know it's possible.
Here's the scenario: I have a list of paths selected by the user, and for each path, I need to create a div with three checkboxes - add, edit, and delete.
Let's say the user selects two paths: '/foo' and '/bar'. For these paths, I need to generate the following object based on the checkboxes checked:
[
{path: '/foo', actions: ["add","edit"]},
{path: '/bar' , actions: ["delete"]}
]
The function responsible for creating this object is triggered when the user hits a final submit button. Below is a snippet of the relevant code:
In the component template:
<li v-for = "selectedPath in newProfile.paths">
<Card :card-name="selectedPath">
<h5>{{selectedPath}}</h5>
<base-checkbox :data-path="selectedPath" type = "default" name = "add">Add</base-checkbox>
<base-checkbox :data-path="selectedPath" name = "edit">Edit</base-checkbox>
<base-checkbox :data-path="selectedPath" name = "delete">Delete</base-checkbox>
</Card>
</li>
The JavaScript code includes vanilla JS to handle checkbox selection. The issue arises from using predefined checkboxes within a template, making it cumbersome to access the checked attribute directly. This approach feels clunky and not in alignment with VueJS best practices.
So, how can I successfully construct the desired object based on the checkboxes checked within each div?