[Vuejs]-Get data attribute in vue

0👍

Is shipping methods an array? If so, instead of passing the {{shipping.id}} as the value, you could pass the array index {{index}}. Then, in your updateTotal method you could access the current option with this.shippingMethods[this.shippingMethod].

The whole thing would look like this:

<div class="select">
<select v-model="shippingMethod">
    <option value="{{index}}" v-for="(shipping, index) in shippingMethods" data-price="{{ shipping.amount}}">{{shipping.description}} - {{shipping.amount / 100}}</option>
</select>
    <div class="select__arrow"></div>
</div>


updateTotal: function(event){
    console.log(this.shippingMethods[this.shippingMethod]);
},

Leave a comment