vue+ElementUI 關(guān)閉對話框清空驗證,清除form表單的操作
前面跟大家提到過 elementUI驗證的問題,那么今天就來看看 點擊對話框和關(guān)閉按鈕 怎么清空驗證,清空form表單,避免二次點擊還會有 驗證錯誤的提示
1、首先在你的對話框 取消按鈕 加一個click事件,例如:(ps::callOf里面的addGroupData和ref一 一對應(yīng)起來)
<div slot="footer" class="dialog-footer">
<el-button @click="callOf('addGroupData')">取 消</el-button>
<el-button type="primary" @click="addgroupList('addGroupData');">確 定</el-button>
</div>
2、點擊取消按鈕,關(guān)閉對話框,清除表單驗證
callOf(formName){
this.creatGroup = false;
this.$refs[formName].resetFields();
}
3、對話框右上角的close按鈕(before-close:關(guān)閉前的回調(diào),會暫停 Dialog 的關(guān)閉,function(done),done 用于關(guān)閉 Dialog。 location.reload:刷新整個頁面)
closeDialog(done){
this.$confirm('確認(rèn)關(guān)閉?')
.then(_ => {
done();
location.reload();
})
.catch(_ => { });
}
這樣就設(shè)置好了,不會出現(xiàn) 二次點擊時,錯誤提示還遺留在對話框上
補(bǔ)充知識:vue中按鈕懸停和選中和更新后自動恢復(fù)之前的狀態(tài)
廢話不多說,看代碼~
<template>
//原本的樣式
//點擊保存后的樣式
<Button class="dict-hold" :class="{dict_hold_active:isActive}" @click="saveDict">保存</Button>
</template>
<script>
export default {
data() {
return{
isActive:false
}
},
methods: {
saveDict() {
var thiz = this;
thiz.isActive=true;
console.log('保存', this.selectDict);
if (!this.selectDict || this.selectDict.unid === '0') {
thiz.$Message.error('更新失敗,請重試');
return false;
}
if (!this.selectDict.dictName) {
thiz.$Message.error('請輸入字典名稱');
return false;
}
if (this.selectDict.dictSortid == null) {
thiz.$Message.error('請輸入排序號');
return false;
}
if (!this.currIsType && !this.selectDict.dictValue) {
thiz.$Message.error('請輸入字典值');
return false;
}
this.$store.dispatch('axios_re', {
type: 'post',
url: '/address/updateDict',
data: {
unid: this.selectDict.unid,
dictName: this.selectDict.dictName,
},
success: function (res) {
thiz.$Message.success('更新成功');
thiz.selectDict.title = thiz.selectDict.dictName;
thiz.isActive=false;
},
fail: function (err) {
thiz.$Message.error('更新失敗');
thiz.isActive=false;
}
});
}
}
}
</script>
<style lang="scss" scoped>
.dict-hold {
margin-left: 35px;
width: 90px;
height: 32px;
background:rgba(57, 97, 244, 1);
&:hover{
background-color: #7295FF;
}
}
.dict_hold_active{
margin-left: 35px;
width: 90px;
height: 32px;
background-color: #7295FF;
}
</style>
以上這篇vue+ElementUI 關(guān)閉對話框清空驗證,清除form表單的操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
?用Vue?Demi?構(gòu)建同時兼容Vue2與Vue3組件庫
這篇文章主要介紹了?用Vue?Demi?構(gòu)建同時兼容Vue2與Vue3組件庫,我們通過考慮其功能、工作原理以及如何開始使用它來了解?Vue?Demi,下面我們一起進(jìn)入文章學(xué)起來吧2022-02-02
ElementUI Tree 樹形控件的使用并給節(jié)點添加圖標(biāo)
這篇文章主要介紹了ElementUI Tree 樹形控件的使用并給節(jié)點添加圖標(biāo),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02
Vue3 構(gòu)建 Web Components使用詳解
這篇文章主要為大家介紹了Vue3 構(gòu)建 Web Components使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09

