el-table中设置三个按钮点击不同的按钮改变这条数据状态栏状态的显示
时间: 2024-02-26 12:59:12 浏览: 26
可以通过在 el-table 中使用 el-table-column 的自定义模板来实现这个功能。具体步骤如下:
1. 在 el-table 中定义需要显示的列,其中包括状态栏的列和三个按钮的列。
```html
<el-table :data="tableData">
<el-table-column label="状态" prop="status">
<template slot-scope="scope">
<span v-if="scope.row.status === 'success'">已完成</span>
<span v-else-if="scope.row.status === 'error'">失败</span>
<span v-else>进行中</span>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button @click="handleSuccess(scope.row)">成功</el-button>
<el-button @click="handleError(scope.row)">失败</el-button>
<el-button @click="handleInProgress(scope.row)">进行中</el-button>
</template>
</el-table-column>
</el-table>
```
2. 在组件中定义三个方法来处理按钮的点击事件,修改数据的状态。
```js
methods: {
handleSuccess(row) {
row.status = 'success';
},
handleError(row) {
row.status = 'error';
},
handleInProgress(row) {
row.status = 'inProgress';
},
}
```
这样,当用户点击按钮时,对应数据的状态栏状态就会更新。注意,这里的 tableData 是组件中定义的数据源。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)