0.1.1 • Published 4 years ago

vue3-fancy-autocomplete v0.1.1

Weekly downloads
-
License
-
Repository
github
Last release
4 years ago

Installation

Using npm

npm install vue3-fancy-autocomplete

Using yarn

yarn add vue3-fancy-autocomplete

Preview

npm.io

Usage

<template>
  <AutoComplete
    v-model="result"
    :options="options"
    :loading="false"
    :debounce="300"
    @input="handleInput"
    @change="handleChange"
    @focus="handleFocus"
    @blur="handleBlur"
  >
    <!-- you can custom loading content with slot -->
    <template #loading>
      searching...
    </template>
  </AutoComplete>
</templete>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { AutoComplete } from 'vue3-fancy-autocomplete'

const fakeApi = (val: string) => new Promise(resolve => {
  setTimeout(() => {
    resolve({
      data: ['a', 'b', 'c']
    })
  }, 300)
})

export default defineComponent({
  components: {
    AutoComplete
  },
  setup() {
    const result = ref('')
    const options = ref<string[]>([])
    const loading = ref(false)

    // if you set debounce > 0
    // the event bind on @change will be debounced
    const handleChange = (inputValue: string) => {
      loading.value = true
      fakeApi(result.value)
        .then(res => {
          result.value = res.data
        })
        .finally(() => {
          loading.value = false
        })
    }

    const handleInput = (inputValue: string) => {}
    const handleFocus = (e: Event) => {}
    const handleBlur = (e: Event) => {}

    return {
      result,
      options,
      loading,
      handleInput,
      handleChange
    }
  }
})
</script>
0.1.1

4 years ago

0.1.0

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago