Reputation: 1399
I want to add a button only to the first row of a table column (labeled with 'Option' in the example code). Is there any simple way to check the row index for v-if v-if="scope.row.index === 0"
? scope.row.index
wont work here.
<el-table :data="mydata">
<!-- more columns -->
<el-table-column prop="option" label="Option">
<template slot-scope="scope">
<div v-if="scope.row.index === 0">
<el-row>
<el-col>
<el-input v-model="scope.row.option"/>
</el-col>
<el-col>
<el-button @click="">Check</el-button>
</el-col>
</el-row></div>
<div v-else>
<el-input v-model="scope.row.option" />
</div>
</template>
</el-table-column>
<!-- more columns -->
</el-table>
Upvotes: 3
Views: 22699
Reputation: 12176
vue template
& scope.$index
my solution:
<el-table
:data="tableData"
border
class="app-downlaod-guide-table"
style="width: 100%">
<el-table-column
v-for="({
prop,
label,
align,
width,
slot,
}, i) in channelClomuns"
:key="prop + i"
:prop="prop"
:width="width"
:align="align"
:label="label">
<template
slot-scope="scope"
v-if="prop === `putLink`">
<a
target="_blank"
href="tableData[scope.$index].putLink">
{{tableData[scope.$index].putLink}}
</a>
</template>
</el-table-column>
</el-table>
Upvotes: 2
Reputation: 1399
I found a solution to this by using the $index
variable, which is the index of the current row.
<div v-if="scope.$index === 0">
Upvotes: 9