<el-button> 取消按钮 取消后刷新页面
时间: 2023-10-15 22:02:13 浏览: 41
可以使用以下代码来实现你的需求:
```html
<template>
<div>
<el-button type="primary" @click="submitForm">提交</el-button>
<el-button @click="cancelForm">取消</el-button>
</div>
</template>
<script>
export default {
methods: {
submitForm() {
// 提交表单的逻辑
},
cancelForm() {
location.reload(); // 刷新页面
}
}
}
</script>
```
在上面的代码中,我们使用了 `location.reload()` 方法来刷新页面。当用户点击取消按钮时,这个方法会被调用,从而刷新页面。同时,我们也定义了一个 `submitForm()` 方法来处理表单的提交逻辑。
相关问题
<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 :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>怎么实现点击添加之后刷新表单页面
可以在添加按钮的点击事件中,调用 `this.$forceUpdate()` 方法,来强制刷新表单页面。具体代码可以这样写:
```javascript
<el-button @click="addToSelectedData; $nextTick(() => $forceUpdate())" style="height: 40px;" :clearable="false">添加</el-button>
```
在点击添加按钮之后,首先执行 `addToSelectedData` 方法,然后使用 `$nextTick` 方法来在 DOM 更新后执行 `$forceUpdate` 方法,从而实现刷新表单页面的效果。