-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
235 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: 'Custom Option Label and Value properties' | ||
--- | ||
|
||
# Custom Option Label and Value properties | ||
|
||
::: warning | ||
This isn't a common use-case. You should use the `label` and `value` properties of the option object when possible. | ||
Doing this will break the type-safety of the component. | ||
Read more about [`getOptionLabel` and `getOptionValue` props](../props.md). | ||
::: | ||
|
||
In the rare case you need to use different properties for the `label` and `value` of an option, you can use the `getOptionLabel` and `getOptionValue` props. | ||
|
||
If you're using TypeScript, be sure to read the [type-safety guide for these props](../typescript.md#using-custom-label-value-with-options) section. | ||
|
||
<script setup> | ||
import { ref } from "vue"; | ||
|
||
import VueSelect from "../../src"; | ||
|
||
const selected = ref(""); | ||
</script> | ||
|
||
<VueSelect | ||
v-model="selected" | ||
:get-option-label="option => option.id" | ||
:get-option-value="option => option.key" | ||
:options="[ | ||
{ id: 'France', key: 'fr' }, | ||
{ id: 'USA', key: 'us' }, | ||
{ id: 'Germany', key: 'de' }, | ||
]" | ||
/> | ||
|
||
## Demo source-code | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
import { ref } from "vue"; | ||
import VueSelect from "vue3-select-component"; | ||
const selected = ref(""); | ||
</script> | ||
<template> | ||
<VueSelect | ||
v-model="selected" | ||
:get-option-label="option => option.id" | ||
:get-option-value="option => option.key" | ||
:options="[ | ||
{ key: 'fr', id: 'France' }, | ||
{ key: 'us', id: 'USA' }, | ||
{ key: 'de', id: 'Germany' }, | ||
]" | ||
/> | ||
</template> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.