0

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'}
        ]
    }
 });

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.