vue.js - 如何更改被破坏的 v-dialog 组件的数据属性?
问题描述
我有内部表单的对话框组件。我想errorMessage
在对话框关闭时删除数据属性。我不能这样做,因为 functiondestroyed()
对它不起作用,它只是添加了 class display:none
。
当我关闭对话框模式时,如何删除此错误消息?
<template>
<v-dialog v-model="modal" max-width="800px">
<template v-slot:activator="{ on }">
<v-btn
v-on="on"
:disabled="disabled">
open dialog
</v-btn>
</template>
<v-card>
<v-card-text>
<v-alert class="mb-4" :value="true" v-if='errorMessage' type="error">{{errorMessage}}</v-alert>
</v-card-text>
<v-btn
@click="downloadParameters"
:loading="loading"
class="success">
Create excel
</v-btn>
</v-card>
</v-dialog>
</template>
<script>
export default {
props: {
disabled: {
type: Boolean,
default: false
},
},
data () {
return {
modal: false,
loading: false,
errorMessage: null
}
},
methods: {
onCancel () {
this.modal = false;
},
downloadParameters:async function(){
const requestBody = {
startDate: this.date,
endDate: this.dateEnd
};
this.loading = false;
this.errorMessage = null;
try {
this.loading = false;
const res = await this.$store.dispatch(url,requestBody);
} catch (e) {
this.loading = false;
this.errorMessage = 'Error message';
}
},
},
created() {
this.errorMessage = '';
}
}
</script>
解决方案
您可以为此使用Vue watcher
watch: {
model(newVal) {
if (!newVal) {
this.errorMessage = null
}
}
}
推荐阅读
- django - 有没有办法将 django 模板变量变量变成 for 循环
- php - 根据属性自动将运输类别分配给 WooCommerce 变体
- django - 为什么 Django 在每次 docker-container 重新启动时重新创建数据库表?
- python - 如何从 Nike 抓取产品的可用尺寸
- google-cloud-platform - Google 专业云架构师考试 - BigQuery 与 Cloud Spanner
- javascript - React 中的条件对象属性
- typescript - 通过从接口中提取类型来创建接口
- excel - 将多个参数传递给函数以检查数组中的重复值
- angular - Angular 8:FormGroup 更新后不禁用材质输入
- java - 错误:找不到符号方法 setAdListener(
) & ( )