n How to reset validation inside methods in Vuejs | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

You need to put the reset inside Vue.nextTick and then it'll work.

you can use:

Vue.nextTick(() => {
      this.$v.$reset()
    });

or

 

this.$nextTick(() => { this.$v.$reset() })

 

Example how to use Vue::nextTick():

 

// the component
export default {
	data() {
		return {
			foo: null,
			bar: null
		}
	},
	validations: {
		foo: {
			required,
			minLength: minLength(5),
			maxLength: maxLength(15)
		},
		bar: {
			required
		}
	},
	methods: {

		onFormSubmit() {
			
			// this works even better - using Vue.nextTick method
			this.$nextTick(() => { this.$v.$reset() })
                        // reset your fields here
		}
	}
}

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook