如果vue js中存在类别,如何显示消息



我有一个函数来检查类别是否存在。但在这里,我面临着一个问题,当检查重复类别时,它工作正常。

但当在模板中调用这个时,它现在工作正常。

<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>

功能是

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;
}

在这里,我的场景是,当类别存在时,它必须像这样显示不允许重复条目否则它将像这样显示按enter键创建一个新条目

使用严格相等而不是includes((

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

最新更新