docs: add CommandPalette async search example

This commit is contained in:
Benjamin Canac
2023-05-17 15:13:34 +02:00
parent c834f401cd
commit 2bdeb04f56
2 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<script setup>
const groups = computed(() => {
return [{
key: 'users',
label: q => q && `Users matching “${q}”...`,
search: async (q) => {
if (!q) {
return []
}
const users = await $fetch(`https://jsonplaceholder.typicode.com/users`, { params: { q } })
return users.map(user => ({ id: user.id, label: user.name, suffix: user.email }))
}
}].filter(Boolean)
})
</script>
<template>
<UCommandPalette :groups="groups" :autoselect="false" />
</template>