2👍
✅
This statement just evaluates whether the wrongNumber
method exists on the Vue instance, which will always be true
:
if (this.wrongNumber) {
You should call the method and evaluate the result:
if (this.wrongNumber()) {
Or, you might be getting the use of Vue methods confused with the use of Vue computed properties.
If you made wrongNumber
a computed property, you could access the returned value via this.wrongNumber
like you are trying to do:
methods: {
isNumeric: function (n) {
return !isNaN(parseFloat(n)) && isFinite(n);
},
validateForm: function (event, $modal) {
if (this.wrongNumber) {
event.preventDefault();
toastada.error('The squares field must contain a number value!');
return;
}
this.saveData($modal);
return true;
},
},
computed: {
wrongNumber: function () {
return this.isNumeric(this.number) === false
},
}
Source:stackexchange.com