Answer the question
In order to leave comments, you need to log in
How to check data before changing data in vue.js?
Good afternoon, there is an input field, how can I check the input data, if they do not pass validation, then do not change the variable?
let app = new Vue({
el: '#productsCart',
data: {
quantity: 5
},
//вочер срабатывает после того как пользователь
watch: {
quantity: function (newData, oldData) {
console.log(oldData)
}
},
})
Answer the question
In order to leave comments, you need to log in
Well, create a method in it, write validation, if validation passes, change the variable.
Make two objects with data - one connected to the fields through the model, which will reflect their state, and the other validated data to send.
Here's how to keep track of data changes in the object associated with the fields and transfer it to the object for sending when they are valid.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question