|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { Option } from "../../src"; |
| 3 | +import { ref } from "vue"; |
| 4 | +import VueSelect from "../../src"; |
| 5 | +
|
| 6 | +const selected = ref<string | null>(null); |
| 7 | +const search = ref<string | null>(null); |
| 8 | +
|
| 9 | +const options = ref<Option<string>[]>([ |
| 10 | + { label: "Alice's Adventures in Wonderland", value: "alice" }, |
| 11 | + { label: "A Wizard of Earthsea", value: "wizard" }, |
| 12 | + { label: "Harry Potter and the Philosopher's Stone", value: "harry_potter_1" }, |
| 13 | + { label: "Harry Potter and the Chamber of Secrets", value: "harry_potter_2" }, |
| 14 | +]); |
| 15 | +
|
| 16 | +const handleCreateOption = (value: string) => { |
| 17 | + options.value.push({ label: value, value }); |
| 18 | + selected.value = value; |
| 19 | +}; |
| 20 | +</script> |
| 21 | + |
| 22 | +<template> |
| 23 | + <p class="selected-value"> |
| 24 | + Search text: {{ search }} |
| 25 | + </p> |
| 26 | + |
| 27 | + <VueSelect |
| 28 | + v-model="selected" |
| 29 | + :options="options" |
| 30 | + :is-multi="false" |
| 31 | + :is-taggable="true" |
| 32 | + placeholder="Pick a book" |
| 33 | + @option-created="(value) => handleCreateOption(value)" |
| 34 | + @search="(value) => search = value" |
| 35 | + > |
| 36 | + <template #taggable-no-options="{ option }"> |
| 37 | + <div class="custom-taggable-no-options"> |
| 38 | + Create option: {{ option }} |
| 39 | + </div> |
| 40 | + </template> |
| 41 | + </VueSelect> |
| 42 | + |
| 43 | + <p class="selected-value"> |
| 44 | + Selected book value: {{ selected || "none" }} |
| 45 | + </p> |
| 46 | +</template> |
0 commit comments