在eldmentui的table表格中,给按钮的type属性附不同的值
时间: 2023-07-15 18:10:11 浏览: 46
在 ElementUI 的 Table 组件中,可以通过设置按钮的 `type` 属性来改变按钮的样式,可用的值包括:
- `primary`:主要按钮,通常为蓝色
- `success`:成功按钮,通常为绿色
- `warning`:警告按钮,通常为黄色
- `danger`:危险按钮,通常为红色
- `info`:信息按钮,通常为青色
以下是示例代码:
```html
<template>
<el-table :data="tableData">
<el-table-column label="姓名" prop="name"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="primary" @click="handleEdit(scope.row)">编辑</el-button>
<el-button type="success" @click="handleSave(scope.row)">保存</el-button>
<el-button type="warning" @click="handleDelete(scope.row)">删除</el-button>
<el-button type="danger" @click="handleCancel(scope.row)">取消</el-button>
<el-button type="info" @click="handleInfo(scope.row)">详情</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: '张三', age: 18 },
{ name: '李四', age: 20 },
{ name: '王五', age: 22 }
]
}
},
methods: {
handleEdit(row) {
console.log('点击了编辑按钮', row)
},
handleSave(row) {
console.log('点击了保存按钮', row)
},
handleDelete(row) {
console.log('点击了删除按钮', row)
},
handleCancel(row) {
console.log('点击了取消按钮', row)
},
handleInfo(row) {
console.log('点击了详情按钮', row)
}
}
}
</script>
```