【问题标题】:Hidden errors when i type back with vuejs当我用 vuejs 输入时隐藏的错误
【发布时间】:2022-01-24 01:40:22
【问题描述】:

当我更改页面时,表单的错误仍然存​​在,我希望它们在我更改页面后消失,而不是当我返回页面时,我总是查看它们。我该怎么办?

这是我的错误

<template>
  <b-form @submit="onSubmit">
    <div v-if="getError">
  <div v-for="(_errors, key) in getError">
   <b-alert
      v-for="error in _errors"
      show
      variant="danger"> 
   
      <h2>{{ formatKey(key) }} :</h2>
      <li>{{ error }}</li>
    </b-alert>
  </div>
</div>

这是我的 js

    
  computed: {
    ...mapGetters([
      'getError'
    ]),

  methods : {
    starDate() {
      return Date.now()
    },
    highlightFrom (elem) {
      this.validate_start = true
      this.disabledDates.to = elem
    },
    validate (elem){
      return elem !== null && elem !== ''
    },
    setSelected(value) {
     this.hiring_contract_category = value;
     this.contract = value === 'contract';
    },
    async onSubmit(event) {
      this.errors = false;
      this.$store.commit('commit_contractable_id', this.id)
      await this.$store.dispatch('create_contract', this.form)
    },


     formatKey (key) {
      return this.$t('vue.' + key.replace('contract_data.', ''))
    }

【问题讨论】:

    标签: javascript forms vue.js vuejs2


    【解决方案1】:

    当你的组件被挂载时尝试清除。

    mounted() {
      // commit to store using mutation (you will need to update your store with method...
      this.$store.commit('clear_errors')
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多