vue+element实现列表行操作按钮打开对话框,在对话框点击提交立即关闭对话框且列表行操作按钮15内禁用
时间: 2024-05-03 11:22:35 浏览: 12
可以使用Vue Element的弹框组件el-dialog和按钮组件el-button来实现列表行操作按钮打开对话框,在对话框点击提交立即关闭对话框且列表行操作按钮15内禁用的效果。
1. 在列表中添加操作按钮,点击按钮打开对话框
```html
<el-table :data="tableData">
<el-table-column>
<!--其他列内容省略-->
<template slot="header">
<span>操作</span>
</template>
<template slot-scope="scope">
<el-button @click="handleEdit(scope.row)">编辑</el-button>
</template>
</el-table-column>
</el-table>
```
```javascript
export default {
data() {
return {
tableData: [
// 数据省略
],
dialogVisible: false, // 对话框是否可见
dialogData: null // 对话框中的数据
};
},
methods: {
handleEdit(row) {
this.dialogData = row;
this.dialogVisible = true;
}
}
};
```
2. 在对话框中添加表单和提交按钮
```html
<el-dialog :visible.sync="dialogVisible" title="编辑" :close-on-click-modal="false">
<el-form :model="dialogData">
<!--表单项省略-->
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="handleSubmit">确 定</el-button>
</div>
</el-dialog>
```
```javascript
export default {
data() {
return {
// 数据省略
submitDisabled: false // 提交按钮是否禁用
};
},
methods: {
handleSubmit() {
// 提交表单数据的逻辑
this.submitDisabled = true; // 禁用提交按钮
setTimeout(() => {
this.dialogVisible = false; // 关闭对话框
this.submitDisabled = false; // 恢复提交按钮
}, 15000);
}
}
};
```
3. 在提交按钮上添加禁用状态
```html
<el-dialog :visible.sync="dialogVisible" title="编辑" :close-on-click-modal="false">
<el-form :model="dialogData">
<!--表单项省略-->
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" :disabled="submitDisabled" @click="handleSubmit">确 定</el-button>
</div>
</el-dialog>
```
这样就实现了列表行操作按钮打开对话框,在对话框点击提交立即关闭对话框且列表行操作按钮15内禁用的效果。