你好,我将数据传递到组件“模态”时遇到问题,我使用带有bootstrap-vue组件的模态,并且我需要传递索引,这是我尝试做的
<table class="table table-striped" v-show="Questions.length!=0">
<tr v-for="Question in Questions">
<td>{{$index + 1}}</td>
<td>{{ Question.text }}</td>
<td>
<button v-on:click="showmodal = true" class="btn btn-default" >Manage</button>
<modal :show.sync="showmodal" width="400">
<div slot="modal-header" class="modal-header">
<h4 class="modal-title">Manage Question</h4>
</div>
<div slot="modal-body" class="modal-body">
<div class="input-group col-lg-6">
<input type="text" class="form-control" value="{{ Questions[$index].text }}"></input>
<span class="input-group-btn"><button v-on:click="AddQuestion" class="btn btn-default">Save Question</button></span>
</div>
</div>
<div slot="modal-footer" class="modal-footer">
<button type="button" class="btn btn-default" v-on:click='showmodal = false'>Exit</button>
<button type="button" class="btn btn-success" v-on:click='showmodal = false'>Custom Save</button>
</div>
</modal>
<button class="btn btn-danger" v-on:click="DeleteQuestion($index)">Delete</button>
</td>
</tr>
提示:传递给index中的模式的数据是最后一个索引,即使该模式位于循环内
使用Vue道具:http://vuejs.org/guide/components.html#Props
在您的示例中:
<modal :show.sync="showmodal" :index="$index" width="400">
...
</modal>
然后在您的Vue模态组件中:
props: ['index']
然后,您将可以访问index
组件内部,就像其他任何属性一样:this.index
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句