0

So I'm using Vuelidate to validate my forms. I've tried to create my own validation helper using the plugins docs but It seems to give me "Cannot read property '__isVuelidateAsyncVm' of undefined" error when i try with the axios request. But if i just return true or if I check if the input is equal to a value "a username" it works just as intended.

I've tried to a number of things. My current attempt is: which gives me the error: Cannot read property '__isVuelidateAsyncVm' of undefined

export function isUser(value) {
  if(value === "") return true;
  this.$http.get('/api/user/check/'+ value).then((response) => { // this.$http = Axios.get
    console.log(response.data);
    return response.data; // returns true or false
  })
}

This one doesn't give and error and "works" but always returns as false which forces the error to come up.

export function isUser(value) {
  var isUser;
  this.$http.get('/api/user/check/'+ value).then((response) => {
    console.log(response.data) // returns true if value matches a username
    isUser = response.data
  });
  console.log(isUser); // Returns undefined
  return isUser ? true : false
}

I've also tried to use the lazy function. v-model.trim.lazy="$v.username.$model"> but it also didn't change anything and I would prefer it doing it on the fly without .lazy

Gopal Kildoliya
  • 649
  • 5
  • 21
Riley
  • 153
  • 3
  • 3
  • 13
  • Yeah, I have another console log inside and it shows the data. I just can't figure out how to get the data properly and return it. – Riley Aug 30 '19 at 05:46
  • `return $this.http.get(...)` will return a promise that you can consume with whatever is calling `isUser()` – Phil Aug 30 '19 at 05:48

0 Answers0