Learn to implement data binding with multiple array inputs in Vue.js

When using Vue.js for form input, I encountered an issue with my new form. Unlike a single input where the v-model and data binding work perfectly, they seem to fail on this new form. You can view the form structure below:

In this new form, the v-model does not seem to work properly.

  <script type="x-template" id="form-input">
         <div class="field">
                        <div class="field-body">
                  
                        <div class="field">
                        <label class="label">Nama Barang: </label>
                        <p class="control is-expanded">
                            <input 
                            type="text"
                            id="nama_barang"
                            class="input"
                           // v-model="userData.nama_barang" ---> if i add this v-model like this this form not showing , if i remove this its work , but i need v-model to store data
                            placeholder="nama barang">
                        </p>
                        </div>
                        
                            <div class="field">
                            <label class="label">Satuan: </label>
                            <p class="control is-expanded">
                                <input 
                                type="text"
                                id="satuan"
                                class="input"
                               // v-model="userData.satuan" ---> if i add this v-model like this this form not showing , if i remove this its work , but i need v-model to store data
                                 placeholder="Satuan">
                            </p>
                            </div>
                           
                            <div class="field">
                             <label class="label">Quantity:</label>
                            <p class="control is-expanded">
                                <input 
                                type="number"
                                id="qtt"
                                class="input"
                                //v-model="userData.qtt" ---> if i add this v-model like this this form not showing , if i remove this its work , but i need v-model to store data
                                placeholder="Qtt" >
                            </p>
                            </div>
                            
                            <div class="field">
                            <label class="label">Harga:</label>
                                <p class="control is-expanded">
                                    <input class="input" 
                                    type="number"
                                    id="harga"
                                    //v-model="userData.harga" ---> if i add this v-model like this this form not showing , if i remove this its work , but i need v-model to store data
                                    placeholder="Harga">
                                </p>
                            </div>

                            <div class="field">
                            <label class="label">Harga Total:</label>
                                <p class="control is-expanded">
                                    {{(userData.qtt * userData.harga) | currency}} // its didnt work because this v-model didnt work
                                </p>
                            </div>
                            
                    </div>
                </div>

Here is my export default section for reference:

 export default {
    data(){
        return{
            fields: [],
            count: 0,
            userData:[{
                rek_id:'',
                tgl_pengajuan:'',
                suplier_id:'',
                status:'Aktif',
            }],
            rek:{},
            suplier:{},
            fields: [],
            count: 0,

        }
    },
    
    components:{
       
    },
    methods:{
        submit() {
            this.errors = {};
            axios.post('/pengadaan/store_induk_pencairan', this.userData).then(response => {
                window.location = response.data.redirect;
            }).catch(error => {
                if (error.response.status === 422) {
                this.errors = error.response.data.errors || {};
                }
            });
            },
        addFormElement: function(type) {
            this.fields.push({
                'type': type,
                id: this.count++
              });
            },
            
    },

I'm looking for a solution to make the v-model on the new form work consistently across all forms, rather than just on the first one.

Answer №1

The variable "userData" is an array, yet you are referencing it as if it were a JavaScript object within the v-model

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

Simplified method for utilizing plugins with the composition api in vue 3

When incorporating vuex or vue-router as plugins in Vue and utilizing the options API, access to these plugins can be achieved using the this keyword. main.js import { createApp } from 'vue'; import i18n from '@/i18n'; import router fr ...

An issue has been encountered with the Vue Router within the Micro Front End/Web Components setup, displaying the error message: "Uncaught TypeError:

I encountered an issue that I need help with. Here is the scenario: I have built a Vue application called my-admin micro app consisting of 4-5 screens/components (manage user, manage notifications, manage roles, etc.). I created a router.js file where I d ...

Leveraging v-model with a bespoke component

Currently, the input field is empty when I start typing and I want to see this data in the console. What could be the issue with my code? HTML: <products-list v-model="product.name" v-on:keyup="productName"></products-list> ...

VS Code sees JavaScript files as if they were Typescript

I have recently delved into the world of Typescript and have been using it for a few days now. Everything seems to be working smoothly - Emmet, linting, etc. However, I've encountered an issue when trying to open my older JavaScript projects in VS Cod ...

Scrolling to an id element in Vue.js can be achieved by passing the ID in the URL using the "?" parameter. This

My challenge involves a URL http://localhost:8080/?london that needs to load directly to the element with an id of london in the HTML section <section id="london"> on the page. Using http://localhost:8080/#london is not an option, even though it woul ...

What is the reason behind using V-for to show identical code instead of the actual values stored in the object?

I am currently learning Vue.js and practicing using the loop feature in it. However, I am facing an issue where when I try to retrieve data from my app.js file into my welcome blade file, it only displays the variable I wrote in the code rather than showin ...

What is the recommended way to update pinia state variables?

When working with Pinia in a Vue.js application, what is the preferred approach: defining state variables in action functions within Pinia and switching them that way, or importing the state variable directly into the component and modifying it there? Whic ...

Tips for extracting nested data in Vue.js without redundancy

Here's a query regarding my "Avatar database" project. I am aiming to gather all tags from each avatar and compile them into a single array without any duplicates. For instance, if there are 3 avatars tagged as "red", the list in the array should onl ...

Exploring the possibilities with Vue 3, Vite, and ZoomSDK

I am encountering difficulties while integrating the Zoom Meetings SDK with Vue 3 and Vite. This is a basic setup of a Vue 3 project using the Vue-create CLI. I have also registered my app with Zoom and obtained my SDK key and SDK secret. Following the i ...

Creating a wrapper Vue component in Solara is a simple process that involves encapsulating specific

I need assistance with creating a new Vuejs component in Solara that will wrap its children components. Despite my expectations, the children components are not rendering inside the default slot of the component. How can I modify the code to ensure that th ...

Remove repeated selections in a dropdown menu using Vue JS

Could someone offer me some assistance, please? I have 3 dropdown menus that need to display specific subjects based on previous selections. One issue I'm facing is how to remove the initial selection in menu one from both menu two and menu three? I ...

Populate the Vue.js2 canvas graph with dynamically assigned array values

I am attempting to fill a canvas graph with random array values. Utilizing the Vuejs2 library, I have implemented the template for displaying the graph data as shown in the code below: import {Line} from 'vue-chartjs' export default Line.extend ...

Tips for transferring information from a cshtml view to a Vue.js application and further into a Vue component

As a beginner in Vue.js, I am exploring the process of passing data from a cshtml view to a Vue app, then transmitting it further to a Vue component within the app for rendering. In my attempt to pass the data, I decided to use a data attribute within the ...

Is it possible to create a multi-page single-page application using Vue js SSR?

It may appear contradictory, but I struggle to find a better way to express it. When using vue server-side rendering, it seems you are limited to single page applications. However, for various reasons, I require an application with multiple real server-s ...

Bidirectional data binding with VDataTable in Vue using JSX syntax

One challenge I am facing is implementing a simple 2-way data binding with the props sortBy and sortDesc in a VDataTable within vue + jsx. To achieve this, I tried setting the attributes as data in my template, where the items of the table are handled as ...

I'm uncertain about how to preview the Nuxt3 application that I've generated

After creating a Nuxt3 in static mode, I want to preview it without having to push it to Netlify every time. My nuxt.config.js remains unchanged: import { defineNuxtConfig } from 'nuxt' export default defineNuxtConfig({ }) However, when trying ...

Mapping custom colors to paths in D3 Sunburst visualizations can add a vibrant and unique touch

Currently, I am in the process of developing a D3 Sunburst Vue component and utilizing the npm package vue-d3-sunburst for this purpose. To access the documentation for the package, please visit: https://www.npmjs.com/package/vue-d3-sunburst The document ...

A dynamic update of the outlined property in a Vuetify v-btn

I am working with a Vuetify button component. <v-btn class="ma-2" tile :outlined="is_outlined" color="success"> <v-icon left>mdi-pencil</v-icon> Edit </v-btn> I am trying to programmatically change the outlined property of th ...

Store JWT as a cookie in Vue JavaScript and ensure it is successfully saved before proceeding

Upon logging in, my page sends the login and password information to the backend, receives a jwt token in return, saves it to the cookies, and redirects to /home. However, there seems to be an issue with the authentication check on the /home route. When c ...

Struggling with xml2js within the Quasar framework version 2.6.0

To integrate the following code into a Quasar 2.6.0 application, I am encountering an issue that needs attention. async fetchAbstracts() { try { const url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=33888705,183 ...