V-For with a Twist: Dynamic V-Model

UPDATE Here is a recreation of the issue I am facing

I need to dynamically bind with the correct index, how can I achieve this?


CLICK THE CODEPEN LINK ABOVE FOR THE OLD CODE CLICK THE CODEPEN LINK ABOVE FOR THE OLD CODE

<template>
  <div>
    <ul class="filters">
      <form action>
        <li v-for="(filter , index ) in filters " :key="filter.id">
          {{index}}
          <label for="filters">{{filter.title }} ({{filter.count}})</label>
          <input
            type="text"
            name="filters"
            :id="index+filter.title"
            :placeholder="filter.title"
            v-model="choosenFilters[0][index]"
          />
          <input
            type="checkbox"
            name="filters"
            :id="filter.title"
            :value="filter.title"
            v-model="choosenFilters[0][index]"
          />
        </li>
      </form>
    </ul>
  </div>
</template>

CLICK THE CODEPEN LINK ABOVE FOR THE OLD CODE CLICK THE CODEPEN LINK ABOVE FOR THE OLD CODE

<script>
export default {
  name: "FilterConfigurationPanel",
  data() {
    return {
      checked: false,
      choosenFilters:{
        name:'', 
        label:'', 
        checked:'', 
      }, 
      shown: null,
    };
  }, 

  created() {
    this.$store.dispatch("filtersAPi");
  },

  computed: {
    ...mapState(["filters"]),
  }, 
};
</script>

Answer №1

Eliminate the need for 2 separate arrays by modifying the existing persons object array to accommodate a new email ID. Simply add two additional properties, newEmail and checked, to each object within the persons array. This will allow you to utilize the same object for display purposes.

<li v-for="(person, index ) in persons" :key="person.id">
  {{person.email}}

  <input type="text" name="filters" v-model="person.newEmail" />
  <input type="checkbox" name="filters" v-model="person.checked" />

By implementing this approach, you can conveniently manage both the id and oldEmail within the array.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In vuex, dynamic modules share common data and do not have unique data

Currently, I am facing an issue with an asynchronous API call that returns an array of objects. After receiving this data, I map it to dynamically registered modules in my store. The process looks something like this: dispatch // prior to this dispatch, ...

Issue with Vue Multiselect auto-suggestion functionality

I've been utilizing the [vue-multiselect] library for my project. [1]: https://www.npmjs.com/package/vue-multiselect. Within a form, I have multiple multiselect dropdowns. The issue I'm facing is with the browser's autocomplete feature. I&a ...

Guide to implementing vue i18n $t method in vuex getters for vue 3

How do I incorporate i18n $t into my getters to retrieve a static label? I attempted importing it in the following way: import { i18n } from '../../locales/i18n.js'; const getters = { guaranteePolicies: state => { let guaranteesS ...

Employ a data or computed property that relies on the value of the prop. The prop will be changed

I'm trying to open a modal in Vue, but I keep getting this error message in the console from the navigator: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed ...

`I'm getting an unexpected result when using the click function`

I have been facing an issue with retrieving the updated value from a data controlled by v-model within a component. Despite observing changes in the app and Vue dev tools, whenever I try to console log the data, it consistently displays the previous value ...

Utilize Vue.js methods to reverse the string within a paragraph using the appropriate function

Hello everyone, I've been attempting to implement a function to reverse a string within a paragraph text in vue.js. I've created a method called reverseword to reverse the words and added it to a card using :rule="reverseword()", but un ...

When using the Vuetify data table in single-select mode, choosing one row automatically selects all the other rows

I am having trouble selecting a single row from the table and then emitting the selected item. Currently, when I select one row, all rows become selected but only the first one encountered is saved to the model (as the selected variable). Could you provi ...

What steps can be taken to resolve the error message "Echo is not recognized"?

Currently, I am handling a project with Laravel 7 along with Vue.js and Laravel-echo. The setup involved installing the Laravel Echo library using npm install --save laravel-echo pusher-js within my application. Additionally, the necessary code was include ...

"Combining Node.js, MongoDB, and Vue.js to create a dynamic dependent select dropdown: a step-by-step

Seeking guidance on setting up a dynamic dependent dropdown list using node js, mongoDB and Vue js. As a newcomer to this concept, I'm unsure where to begin. Here is the scenario I am facing: I need assistance in creating 2 dropdown menus for country ...

"PHP and jQuery, a winning combination for handling form

I have recently begun working on the form below and I have a couple of inquiries: Firstly, how could I utilize PHP or Local Storage to store the data from the previous page when the user clicks 'next'? Secondly, is there a way to attach an imag ...

Oops! It seems like there was a mistake. The ReferenceError is saying that Vue is

I've been working on creating a new app, but I keep running into an issue. Unidentified Reference Error: Vue is not recognized. <template> <v-app> <div id="example-1"> <v-btn v-on:click="counter += 1">Add 1</v-bt ...

how to uncheck a checkbox using Vue.js

When the next button is clicked, I want to remove the checked status of the checkbox without using Vue. Here is a demo code snippet: new Vue({ el: "#app", data: { id:0, items: [ {'id':1,'name':'chk-a',&apos ...

Exploring Firebase's Collection Retrieval through Vue.js

Trying to retrieve a specific collection from Firebase Firestore is giving me an error that I haven't been able to resolve yet. Below is the code snippet from my boot file: import { initializeApp } from "firebase/app"; import { getFirestore ...

Having issues with Vue.js when using Vue-strap Radio Buttons

While developing my web application with vue.js, I encountered an issue with radio buttons when I switched to using bootstrap style. I understand that I need to use vue-strap for proper data binding with bootstrap styled radio buttons in vue.js, but I am s ...

Utilizing markers for gaming in a data table with Vue and Vuetify

I am struggling to retrieve the games of teams from two objects with arrays in Vue. One object contains headers for a data table, while the other object contains status information. Despite my efforts, I have not been successful in fetching the game detail ...

Tips for aligning a button to the bottom of a card in Vuetify, regardless of the text length

I'm having trouble aligning buttons in my cards. I have a layout with 3 cards in a row, but the button's position changes when text is added to a specific card. I've tried passing different props and using various classes, but nothing seems ...

The error thrown is Uncaught TypeError: 'this' is not defined in the Vuex

<script setup> import { useLayout } from '@/layout/composables/layout'; import { ref, computed ,onMounted} from 'vue'; import AppConfig from '@/layout/AppConfig.vue'; import auth from '@/auth'; const { layoutC ...

Form featuring many submission buttons

Can anyone help me identify which submit button has been clicked on a form with multiple buttons? $("#my_form").on("submit", function(event) { event.preventDefault(); var form_action = $(this).attr("action"); var form_data = $(this).seri ...

How can Angular CLI prevent the submission of an HTML form unless a previous option has been selected

I am currently working on a form that contains select fields with various options pre-populated. <form [formGroup]="selectVehicleForm"> <select formControlName="Manufacturer"> <option *ngFor='let ...

Guide to Updating Store State with API Data

My goal is to update my component state with data retrieved from an API using a getter in the store. Within the mounted() lifecycle hook, I call the getProducts() getter which is defined as: export const getters = { async getProducts() { axios.ge ...