Skip to content

Commit ff1dc37

Browse files
committed
feat(docs): add pre-selected values for both single & multi modes
Closes #232
1 parent 76a9dc7 commit ff1dc37

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

docs/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default defineConfig({
5454
{ text: "Dropdown menu header", link: "/demo/dropdown-menu-header" },
5555
{ text: "Custom displayed options", link: "/demo/custom-displayed-options" },
5656
{ text: "Controlled menu", link: "/demo/controlled-menu" },
57+
{ text: "Pre-selected values", link: "/demo/pre-selected-values" },
5758
],
5859
},
5960
],

docs/demo/pre-selected-values.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: 'Pre-selected values'
3+
---
4+
5+
# Pre-selected values (single & multi)
6+
7+
The following example demonstrates how to use the `VueSelect` component with pre-selected values.
8+
9+
This can be achieved by setting a value to the `ref` which is passed as a `v-model` to the `VueSelect` component.
10+
11+
<script setup>
12+
import { ref } from "vue";
13+
14+
import VueSelect from "../../src";
15+
16+
const options = [
17+
{ label: 'Option #1', value: 'option_1' },
18+
{ label: 'Option #2', value: 'option_2' },
19+
{ label: 'Option #3', value: 'option_3' },
20+
{ label: 'Option #4', value: 'option_4' },
21+
{ label: 'Option #5', value: 'option_5' },
22+
];
23+
24+
const singleSelected = ref("option_1");
25+
const multiSelected = ref(["option_3", "option_5"]);
26+
</script>
27+
28+
<p>Single select:</p>
29+
30+
<VueSelect
31+
v-model="singleSelected"
32+
:options="options"
33+
/>
34+
35+
<p>Multi select:</p>
36+
37+
<VueSelect
38+
v-model="multiSelected"
39+
:options="options"
40+
:is-multi="true"
41+
/>
42+
43+
## Demo source-code
44+
45+
```vue
46+
<script setup lang="ts">
47+
import { ref } from "vue";
48+
import VueSelect from "vue3-select-component";
49+
50+
const options = [
51+
{ label: "Option #1", value: "option_1" },
52+
{ label: "Option #2", value: "option_2" },
53+
{ label: "Option #3", value: "option_3" },
54+
{ label: "Option #4", value: "option_4" },
55+
{ label: "Option #5", value: "option_5" },
56+
];
57+
58+
const singleSelected = ref("option_1");
59+
const multiSelected = ref(["option_3", "option_5"]);
60+
</script>
61+
62+
<template>
63+
<p>Single select:</p>
64+
65+
<VueSelect
66+
v-model="singleSelected"
67+
:options="options"
68+
/>
69+
70+
<p>Multi select:</p>
71+
72+
<VueSelect
73+
v-model="multiSelected"
74+
:options="options"
75+
:is-multi="true"
76+
/>
77+
</template>
78+
```

0 commit comments

Comments
 (0)