<el-dialog :title="formEditTitle" :visible.sync="dialogEdittVisible" width="700px"> <div style="display: flex; justify-content: center; height: 40px;"> <span style="align-self: center;">总量:</span> <el-input id="input-box" @input="forceUpdate" placeholder="在这里输入内容" v-model="dialogObj.name" style="width: 250px;"></el-input> <div class="radiobox" style="flex: 1; height: 100px; text-align: center; margin-left: 20px;"> <el-form> <span>分项:</span> <el-select filterable v-model="dialogObj.indexName" placeholder="请选择" @change="showSelectedValue" style="flex: 1; height: 100px; text-align: center;"> <el-option v-for="(itemOne, item) in templateList" :key="item" :label="itemOne" :value="itemOne" > </el-option> </el-select> </el-form> </div> <el-button @click="addToSelectedData" style="height: 40px;" :clearable="false">添加</el-button> </div> <el-table :data="dialogObj.children"> <el-table-column prop="name" label="分项"></el-table-column> <el-table-column label="操作"> <template slot-scope="scope"> <el-button @click="deleteSelectedData(scope.$index)">删除</el-button> </template>怎么实现提交之后刷新页面
时间: 2023-07-19 12:03:34 浏览: 258
可以在提交成功后,调用 `location.reload()` 方法刷新页面,示例代码如下:
```javascript
// 在提交成功后调用该方法
submitForm() {
// 提交表单代码
// ...
// 刷新页面
location.reload();
}
```
另外,建议在提交表单时使用 Ajax 异步提交,可以避免页面刷新的问题。例如使用 Axios 库提交表单,示例代码如下:
```javascript
submitForm() {
axios.post('/api/submitForm', this.form).then(response => {
// 提交成功的处理代码
// ...
// 刷新页面
location.reload();
}).catch(error => {
// 提交失败的处理代码
console.error(error);
});
}
```
这样就可以在表单提交成功后,刷新页面并显示最新的数据。
相关问题
<el-dialog :title="formEditTitle" :visible.sync="dialogEdittVisible" width="700px"> <div style="display: flex; justify-content: center; height: 40px;"> <span style="align-self: center;">总量:</span> <el-input id="input-box" @input="forceUpdate" placeholder="在这里输入内容" v-model="dialogObj.name" style="width: 250px;"></el-input> <div class="radiobox" style="flex: 1; height: 100px; text-align: center; margin-left: 20px;"> <el-form> <span>分项:</span> <el-select filterable v-model="dialogObj.indexName" placeholder="请选择" @change="showSelectedValue" style="flex: 1; height: 100px; text-align: center;"> <el-option v-for="(itemOne, item) in templateList" :key="item" :label="itemOne" :value="itemOne" > </el-option> </el-select> </el-form> </div> <el-button @click="addToSelectedData" style="height: 40px;" :clearable="false">添加</el-button> </div> <el-table :data="dialogObj.children"> <el-table-column prop="name" label="分项"></el-table-column> <el-table-column label="操作"> <template slot-scope="scope"> <el-button @click="deleteSelectedData(scope.$index)">删除</el-button> </template>怎么实现提交之后刷新页面
如果你想在提交数据后刷新页面,可以在提交数据成功的回调函数中使用 `window.location.reload()` 方法来刷新页面。举个例子,你可以在提交数据的方法中添加以下代码:
```
axios.post('/submitData', this.formData).then(response => {
// 提交成功后的回调函数
window.location.reload(); // 刷新页面
}).catch(error => {
console.log(error);
});
```
这样,在提交数据成功后,页面就会重新加载并刷新数据。当然,为了避免重复提交数据,你还需要在提交数据的按钮上添加禁用属性,例如:
```
<el-button :loading="submitting" @click="submitData" :disabled="submitting">提交</el-button>
```
其中,`submitting` 是一个响应式的变量,用来表示当前是否正在提交数据。在提交数据方法中,你需要将 `submitting` 设置为 `true`,并在提交成功或失败后将其设置为 `false`。
el-dialog设置关闭按钮位置
在Element UI中,`el-dialog`组件默认的关闭按钮位置是在右上角。如果你需要自定义关闭按钮的位置,可以通过以下几种方式来实现:
1. **使用插槽(Slots)**:
你可以使用`header`插槽来自定义对话框的头部内容,从而改变关闭按钮的位置。
```html
<el-dialog
:visible.sync="dialogVisible"
width="30%">
<template v-slot:header>
<div class="custom-header">
<span class="dialog-title">自定义标题</span>
<button class="close-button" @click="dialogVisible = false">关闭</button>
</div>
</template>
<span>这是一段信息</span>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
</span>
</el-dialog>
```
```css
.custom-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.close-button {
background: none;
border: none;
font-size: 18px;
cursor: pointer;
}
```
2. **使用CSS样式**:
你可以通过覆盖默认样式来调整关闭按钮的位置。
```html
<el-dialog
:visible.sync="dialogVisible"
width="30%">
<span>这是一段信息</span>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
</span>
</el-dialog>
```
```css
.el-dialog__header {
position: relative;
}
.el-dialog__headerbtn {
position: absolute;
top: 10px;
right: 10px;
}
```
3. **使用自定义按钮**:
你可以隐藏默认的关闭按钮,然后使用自定义按钮来控制对话框的关闭。
```html
<el-dialog
:visible.sync="dialogVisible"
width="30%"
:show-close="false">
<span>这是一段信息</span>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
<button class="custom-close" @click="dialogVisible = false">关闭</button>
</span>
</el-dialog>
```
```css
.custom-close {
background: none;
border: none;
font-size: 18px;
cursor: pointer;
position: absolute;
top: 10px;
right: 10px;
}
```
通过以上方法,你可以根据需要自定义`el-dialog`组件的关闭按钮位置。
阅读全文