【问题标题】:How to change data property on destroyed v-dialog component?如何更改被破坏的 v-dialog 组件的数据属性?
【发布时间】:2019-08-06 14:29:21
【问题描述】:

我有一个对话框组件,里面有表单。我想在对话框关闭时删除 errorMessage 数据属性。我不能这样做,因为函数destroyed() 不起作用,它只是添加了类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.js vuetify.js


    【解决方案1】:

    您可以为此使用Vue watcher

    watch: {
      model(newVal) {
        if (!newVal) {
          this.errorMessage = null
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 2020-05-17
      • 2021-10-09
      • 2021-10-09
      • 2012-02-01
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多