Vue.js 引导vue在自定义渲染中单击单元格时获取行数据
我有一个表,在单独的列中有两个自定义字段索引和一个垃圾箱图标,用于删除该行。我想在单元格上单击just trash图标获取行的索引,然后将其从数据对象中的项中删除,但我的问题是我不知道如何在自定义渲染的onclick事件中获取行数据。我该怎么做Vue.js 引导vue在自定义渲染中单击单元格时获取行数据,vue.js,bootstrap-vue,Vue.js,Bootstrap Vue,我有一个表,在单独的列中有两个自定义字段索引和一个垃圾箱图标,用于删除该行。我想在单元格上单击just trash图标获取行的索引,然后将其从数据对象中的项中删除,但我的问题是我不知道如何在自定义渲染的onclick事件中获取行数据。我该怎么做 <b-table :fields="fields" :items="items"> <template v-slot:cell(index)="data"> {{ data.index + 1 }} <
<b-table :fields="fields" :items="items">
<template v-slot:cell(index)="data">
{{ data.index + 1 }}
</template>
<template v-slot:cell(remove)="data">
<i class="fas fa-trash"></i>
</template>
</b-table>
这应该是你想要的。您只需要在垃圾箱图标上单击一个函数,将该行的索引传递给它
<div id="app">
<div>
<b-table :fields="fields" :items="items">
<template v-slot:cell(index)="data">
{{ data.index + 1 }}
</template>
<template v-slot:cell(remove)="data">
<i class="fas fa-trash" @click=removeRow(data.index)></i>
</template>
</b-table>
</div>
</div>
methods: {
removeRow(index) {
this.items.splice(index,1)
}
}
这应该是你想要的。您只需要在垃圾箱图标上单击一个函数,将该行的索引传递给它
<div id="app">
<div>
<b-table :fields="fields" :items="items">
<template v-slot:cell(index)="data">
{{ data.index + 1 }}
</template>
<template v-slot:cell(remove)="data">
<i class="fas fa-trash" @click=removeRow(data.index)></i>
</template>
</b-table>
</div>
</div>
methods: {
removeRow(index) {
this.items.splice(index,1)
}
}
在第二个模板上添加一个带有@click事件处理程序的按钮怎么样。在@click事件上,根据需要传递事件名称和索引,即@click=yourEventdata.indexHow关于在第二个模板上添加带有@click事件处理程序的按钮。在@click事件上,根据需要传递事件名称和索引,即@click=yourEventdata.index