[英]vue js passing data to a component
hello i have a problem with passing data to a component "modal " , i use a modal with bootstrap-vue component and i need to pass the index , here's what i tried to do 您好,我在将数据传递到组件“模态”时遇到问题,我使用了带有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>
hint : the data that passed to the modal in index , is the last index , Even though the modal it's inside the loop 提示:传递给index中的模式的数据是最后一个索引,即使该模式位于循环内
Use Vue props: http://vuejs.org/guide/components.html#Props 使用Vue道具: http : //vuejs.org/guide/components.html#Props
In your example: 在您的示例中:
<modal :show.sync="showmodal" :index="$index" width="400">
...
</modal>
Then inside your Vue modal component: 然后在您的Vue模态组件中:
props: ['index']
You will then be able to access the index
inside the component, like any other property: this.index
然后,您将可以访问组件内部的
index
,就像其他任何属性一样: this.index
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.