Kyaw Zin
Kyaw Zin

Reputation: 3

Vuejs - How to add new value into itemList array

I'm new in Vuejs, please help me - How to add new value into itemList array

    new Vue({
    el: "#app",
    data: {
        rows: [],
        itemList: [
            { code: 'Select an Item', description: '', unitprice: ''},
            { code: 'One', description: 'Item A', unitprice: '10'},
            { code: 'Two', description: 'Item B', unitprice: '22'},
            { code: 'Three', description: 'Item C', unitprice: '56'}
        ]
    }
 });

Upvotes: 0

Views: 82

Answers (1)

chsword
chsword

Reputation: 2062

new Vue({
    el: "#app",
    data: {
        rows: [],
        itemList: [
            { code: 'Select an Item', description: '', unitprice: ''},
            { code: 'One', description: 'Item A', unitprice: '10'},
            { code: 'Two', description: 'Item B', unitprice: '22'},
            { code: 'Three', description: 'Item C', unitprice: '56'}
        ]
    },
    methods:{
      addItem(){
         this.itemList.push({code:'Four',description:'Item D',unitprice:'0'});
      }
    }
 });

You can call addItem, in template or javascript.

Upvotes: 2

Related Questions