Am performing an async validation where i need to access the $axios set globally in vuejs but this fails
Validator.extend('async_validate_job_type', {
getMessage: field => `The Name already exists`,
validate: value => new Promise((resolve) => {
//validate email.
this.$axios.post('/validate/position-type', {email:value})
.then(
....perform stuff here
)
})
});
Now the above throws an error
cannot read propery post of undefined
In other components using this.$axios.post
works. But in the above seems i cannot access this.$axios. Where am i going wrong?
I have already setup axios via
Vue.prototype.$axios = axios.create(axiosConfig);
Also using normal function like this also fails
Validator.extend('async_validate_job_type', {
getMessage: field => `The Name already exists`,
validate(value){
return new Promise((resolve) => {
console.log("value of this is", this); //this is undefined
this.$axios.post())
})
}
});