vuejs / Discussion

Vue.js discussion
167 stars 17 forks source link

How to push to object using a method #1275

Open claudiuionita opened 8 years ago

claudiuionita commented 8 years ago

Hello,

I need to iterate through an exiting html select options, push to object from vue component and then build html vue template based on that object. I have two issues:

  1. Cannot populate exiting object
  2. Cannot call method on ready (I don't want to attach it to any html related events)

The code:

 var addACreditCard = new Vue({
      el: '.add-a-credit-card',
      template: '#add-a-credit-card',
      data: {
        ccExpYear : {
        }
      },
      methods: {                      
        populateExpirationYear: function(){   
          $('#cbExpYear option').each(function(){            
            var option  = $(this).val();             
            this.ccExpYear[option] = option;            
          });
        }
      }
    });

Any ideas?

I've tried to add a new data set, ready : function (){populateExpirationYear() })

Thanks!