Vue API search function example

0 votes
98 views
added Oct 17, 2019 in Vue by LC Marshal Captain (25,770 points)
export async function search(data) {
  return new Promise(async (resolve, reject) => {
    try {
      
      data = {
        ...getDataForList.call(this),
        dynamic_pagination_count: this.perPageCount,
        token: store.state.login.token,
        uid: store.state.login.uid
      };
      if(store.state.login.isAdmin){
        data.ouid = store.state.login.uid
        if(this.listingSearchFilters.username){
          data.username = this.listingSearchFilters.username
        }
        if(this.searchListing) {
          data.username = this.searchListing;
        }
      }
          
      await this.$nextTick();
      this.$eventHub.$emit("show-full-loading");
      
      const res = await this.axios.post("/api/v1/search", qs.stringify(data), {
        auth: this.apiAuth,
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      });
      this.$eventHub.$emit("hide-full-loading");
      
      resolve(res.data);
    } catch (error) {
      this.$eventHub.$emit("hide-full-loading");
      reject(error);
    }
  });
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...