[Vuejs]-Vue-Apollo and query autocomplete

1๐Ÿ‘

โœ…

I found myself the solution and iโ€™ll write it:

methods: {
    filterFn (val, update, abort) {
      if (val.length < 3) {
        abort()
        return
      }
      setTimeout(() => {
        update(() => {
          this.$apollo.query({
            query: gql`query($email: String!) {
              filterUsersListByEmail(
                email: $email
              ) {
                UserId
                UserEmail
              }
            }`,
            variables: {
              email: val,
            }
          }).then(data => {
            var emailList = [];
            for(var i = 0; i < data.data.filterUsersListByEmail.length; i++)
            {
              emailList[i] = JSON.parse('{"label":"' + data.data.filterUsersListByEmail[i].UserEmail + '", "value":"' + data.data.filterUsersListByEmail[i].UserId + '"}');
            }
            this.options = usersList;
          }).catch(error =>{
            console.log({error});        
          });
        })
      }, 1000)


    },
    onReset(){
      ...
    },
  }
๐Ÿ‘คbobc82

Leave a comment