How to show message if category exist in vue js?

Viewed 36

I had a function to check categories is exist or not. But here I am facing one issue when check for duplicate category it is working fine.

but when call this one in template it now working fine.

                 <template v-slot:no-data>
                    <v-list>
                      <v-list-item  v-if="checkForDuplicateCategory()">
                        Duplicate entries not permitted
                      </v-list-item>
                      <v-list-item v-else>
                        No results matching "<strong>{{ bid.search }}</strong
                        >" . Press <kbd>enter</kbd> to create a new one
                      </v-list-item>
                    </v-list>
                  </template>

function is

 checkForDuplicateCategory(bool){
  console.log("Entered to check duplicate categories");
  let newEstimates = this.newEstimates.map((estimate) => {
    return estimate.category?.toLowerCase();
  });
  console.log("New Estimates" , newEstimates);
  if (newEstimates.includes(this.bid.category?.toLowerCase())) {
      return true;
  }
  return false;
}

Here my scenario is when category exist it has to show like this Duplicate entries not permitted else it has show like this Press enter to create a new one

1 Answers

Use Strict equality instead of includes().

checkForDuplicateCategory(){
  this.newEstimates.map((estimate) => {
    return estimate.category?.toLowerCase() === this.bid.category?.toLowerCase()
  });
}
Related