useFuse
useFuse
Fuse.jsを使用して、コンポーザブルでファジー検索を簡単に実装します。
Fuse.jsのウェブサイトから:
ファジー検索とは何ですか?
一般的に言えば、ファジー検索(より正式には近似文字列マッチング)は、与えられたパターンに対しておおよそ等しい文字列を見つける技術です(正確に一致するのではなく)。
Fuse.jsをピア依存関係としてインストール
NPM
npm install fuse.js@^7
Yarn
yarn add fuse.js
使用方法
import { useFuse } from '@vueuse/integrations/useFuse'
import { shallowRef } from 'vue'
const data = [
'John Smith',
'John Doe',
'Jane Doe',
'Phillip Green',
'Peter Brown',
]
const input = shallowRef('Jhon D')
const { results } = useFuse(input, data)
/*
* 結果:
*
* { "item": "John Doe", "index": 1 }
* { "item": "John Smith", "index": 0 }
* { "item": "Jane Doe", "index": 2 }
*
*/
© 2019–PRESENT Anthony Fu https://github.com/antfu
※このページは Nuxt.js 公式ドキュメントの翻訳ページです。
公式ドキュメントの該当ページはこちら:
#