Fuzzy in Vue
Simplify your Vue code with these helpful fuzzy search utilities.
Summary
You can use this library in Vue just like in a regular JavaScript project, but we provide additional helpers to make integration easier.
The key differences are:
- Internal use of
ref
andcomputed
for reactivity - Usage of
watch
for query changes
Basic Example
With just a few lines of code, you can implement fuzzy search that returns matched results:
Why we import from `/vue`?
Its a convention to separate the core library from the Vue library. This way, you can use the core library in other frameworks or even in core JavaScript. With this approach the imported bundle is smaller and the code is more organized.
API
useFuzzy
This is the main hook for the vue adapter, providing a performance-optimized way to search through items.
It accepts the same props as the core fuzzy, plus some additional options:
- list - The ref list of items to search through. Required.
- query - The ref query to search for. Required.
The structure then will always be like this:
Now you are using one step only, you don't need to create the
fuzzy
function and then call it with the query. You can just use useFuzzy
and it will do it for you internally.All useFuzzy
Options
Examples
Static strings list
Object search by one key
Object search by multiple keys
Search exact matches
References
Options
Prop | Type | Default |
---|---|---|
key? | keyof T | undefined |
getKey? | (item: T) => (string | null)[] | undefined |
debug? | boolean | false |
limit? | number | Number.MAX_SAFE_INTEGER |
maxScore? | number | 100 |
mapResult? | MapResult<T, U> | (result) => result.item |
Reponse
Prop | Type | Default |
---|---|---|
results | Result<T>[] | "" |
length | number | 0 |
time | number | 0 |
normalizedQuery | string | "" |
hasExactMatch | boolean | false |
bestMatch | Result<T> | null |
hasResults | boolean | false |
Result
Prop | Type | Default |
---|---|---|
item | NonNullable<T> | null |
score | number | 0 |
matches | Matches | null |
Edit on GitHub
Last updated on