javascript - Vue.js Access v-for $index within a component -


i'm using vue js create form allows user add or remove rows needed.

within container i've created custom dependant component has title reads dependant n n position in data array + 1.

i know should able count within component index variable exists within scope of v-for believe accessing incorrectly within component.

my container markup follows:

<div class="tab-pane" id="dependants"> <p>enter birth date , residential status of dependants below.</p>  <ae-dependant v-for="dependant in dependants" :dob="dependant.dob" :at-home="dependant.athome"></ae-dependant>  <button class="btn btn-primary" type="button" @click="adddependant"><i class="glyphicon glyphicon-plus"></i> add dependant</button> </div> 

i know pass prop feel don't need this.

the component , ancillaries below.

// todo: 2 way filter vue.filter('isodate', function (value) {     return value.toisostring().substr(0,10); })  var dependant = vue.extend({     props: ['dob','athome'],     template: '<div class="form-horizontal">'             + '<h4>dependant {{ index + 1 }}</h4>'             + '<div class="form-group">'             + '<label for="dependantdob{{ index + 1 }}" class="col-sm-2 control-label">date of birth</label>'             + '<div class="col-sm-6">'             + '<input type="date" class="form-control" id="dependantdob{{ index + 1 }}" v-model="dob | isodate">'             + '</div><div class="col-sm-4"><div class="checkbox"><label>'             + '<input type="checkbox" id="dependantres{{ index + 1 }}" v-model="athome"> <b>living @ home?</b>'             + '</label></div></div></div></div>' })  // register vue.component('ae-dependant', dependant)  var dependants = new vue ({     el: '#dependants',     data: {         dependants: [{dob: new date(),athome: true}]     },     methods: {         adddependant: function () {             return this.dependants.push({dob: new date(), athome: true});         }     } }); 

how should accessing index within component?


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -