VueJS Push New Elements Inside an v-for Array in V-Bind

VueJS Push New Elements Inside an v-for Array in V-Bind

In this Post We Will Explain About is VueJS Push New Elements Inside an v-for Array in V-Bind With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to VueJS – Push data into array in V-Bind Example

In this post we will show you Best way to implement How to push data from vuejs, hear for javascript – Push to vuex store array in VueJS with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.




Getting Started for Push to Data store array in VueJS

We have used CDN(libes) for Vuejs so you must need Your internet Data connection for them to work on Dynamic Components in Vue.js.

Also Read :   Display Image Preview Before Upload Multiple Images using jQuery,Ajax And PHP

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.6/vue.js"></script>

index.html

This is the main HTML view of our Simple Web Application. In here, we have init Base declared all our simple live this Example(VueJS – Push data into array in V-Bind) dependencies and the HTML Elements that we have created.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>javascript - Push values to array vueJS</title>
</head>

<body>
<h2>javascript - Push values to array vueJS</h2>
    <div id="live24uApp">
        <div >
            <live-user v-for="(user, index) in userList"
                    :userAllData="itemList"
                    :user="user"
                    v-on:remove="removeUser(index)">
            </live-user>
            {{userList}}
        </div>
        <div>
            <button @click="addUser"> Add Row </button>
        </div>
    </div>


<template id="user-template">
    <div>
        <select v-model="user.user">
            <option v-for="user in userAllData"  :value="user"> {{ user.grade }} </option>
        </select>
        <input type="text" placeholder="Text" v-model="user.user.information">
        <input type="text" placeholder="value" v-model="user.user.age">
        <button v-on:click= "remove"> X </button>
    </div>
</template>
</body>
</html>

index.js

This contains our simple custom index.js files Add Like as javascript, vuejs scripts

<script>

Vue.component('live-user', {
    props: ['userAllData', 'user'],
    template: '#user-template',
    data: function () {
        return {

        }
    },
    methods: {
        remove() {
            this.$emit('remove');
        }
    }
}),

new Vue({
    el: "#live24uApp",
    data: {
        userList: [],
    	itemList: [
            { grade: 'Select an Grade', information: '', age: ''},
			{ grade: 'first', information: 'Grade A', age: '10'},
			{ grade: 'second', information: 'Grade B', age: '22'},
			{ grade: 'third', information: 'Grade C', age: '56'}
        ]
    },

    methods: {

        addUser(){
            this.userList.push({user: ''}); 
        },

        removeUser(index){
            this.userList.splice(index,1);
        }
    }
})
</script>

Full Example : VueJS – Push data into array in V-Bind

simple vuejs and html source grade to run example on VueJS – Push data into array using V-Bind

Also Read :   Vue Shopping Cart Example - Vuejs Shopping Cart | Shopping Cart Application

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Push New Elements Inside an v-for Array from VueJS</title>
</head>

<body>
<h2>VueJS - Push data into array in V-Bind</h2>
    <div id="live24uApp">
        <div >
            <live-user v-for="(user, index) in userList"
                    :userAllData="itemList"
                    :user="user"
                    v-on:remove="removeUser(index)">
            </live-user>
            {{userList}}
        </div>
        <div>
            <button @click="addUser"> Add Row </button>
        </div>
    </div>


<template id="user-template">
    <div>
        <select v-model="user.user">
            <option v-for="user in userAllData"  :value="user"> {{ user.grade }} </option>
        </select>
        <input type="text" placeholder="Text" v-model="user.user.information">
        <input type="text" placeholder="value" v-model="user.user.age">
        <button v-on:click= "remove"> X </button>
    </div>
</template>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.6/vue.js"></script>
<script>

Vue.component('live-user', {
    props: ['userAllData', 'user'],
    template: '#user-template',
    data: function () {
        return {

        }
    },
    methods: {
        remove() {
            this.$emit('remove');
        }
    }
}),

new Vue({
    el: "#live24uApp",
    data: {
        userList: [],
    	itemList: [
            { grade: 'Select an Grade', information: '', age: ''},
			{ grade: 'first', information: 'Grade A', age: '10'},
			{ grade: 'second', information: 'Grade B', age: '22'},
			{ grade: 'third', information: 'Grade C', age: '56'}
        ]
    },

    methods: {

        addUser(){
            this.userList.push({user: ''}); 
        },

        removeUser(index){
            this.userList.splice(index,1);
        }
    }
})
</script>
</body>
</html>

VueJS – Push data into array in V-Bind

Also Read :   How to store dynamic array values using VueJS

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example





Example

I hope you have Got What is How to push Object element to an array in Vuejs And how it works.I would Like to have FeedBack From My Blog(live24u.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(live24u.com) Are Most Always Welcome.