2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-17 02:29:37 +03:00

WIP: v3 – remove onSearch callback prop (#811)

* remove onSearch callback prop

* update ajax docs

* docs formatting

* remove onSearch callback prop
This commit is contained in:
Jeff Sagal
2019-04-08 11:58:04 -07:00
committed by GitHub
parent b5e239c49c
commit 01ecee93d5
5 changed files with 66 additions and 100 deletions
+31 -19
View File
@@ -1,22 +1,25 @@
# AJAX Remote Option Loading
## Loading Options with AJAX
<CodePen url="POMeOX" height="400"/>
The `search` event provides a hook to load options from a parent component
when the search text is updated. It is emitted with two parameters:
**Search Event Parameters**
- `search {String}` The current search string
- `loading {Function}` Accepts a boolean parameter to toggle the loading state
The `onSearch` prop allows you to load options via ajax in a parent component
when the search text is updated. It is invoked with two parameters, `search` & `loading`.
```html
<v-select @search="fetchOptions" />
```
```js
/**
* Accepts a callback function that will be run
* when the search text changes. The callback
* will be invoked with these parameters:
*
* @param {search} String Current search text
* @param {loading} Function Toggle loading class
*/
onSearch: {
type: Function,
default: false
* Triggered when the search text changes.
*
* @param search {String} Current search text
* @param loading {Function} Toggle loading class
*/
fetchOptions (search, loading) {
// ... do some asynchronous stuff!
},
```
@@ -25,7 +28,7 @@ to the vue-select internal `loading` property. Call `loading(true)` to set the
`loading` property to `true` - toggling the loading spinner. After your
asynchronous operation completes, call `loading(false)` to toggle it off.
#### Disabling Filtering
## Disabling Filtering
When loading server side options, it can be useful to disable the
client side filtering. Use the `filterable` prop to disable filtering.
@@ -44,17 +47,26 @@ filterable: {
},
```
#### Loading Spinner
## Loading Spinner
Vue Select includes a default loading spinner that appears when the loading class is present. The `spinner` slot allows you to implement your own spinner.
Vue Select includes a default loading spinner that appears when the loading class is present. The
`spinner` slot allows you to implement your own spinner.
```html
<div class="spinner" v-show="spinner">Loading...</div>
```
#### Library Agnostic
## Library Agnostic
Since Vue.js does not ship with ajax functionality as part of the core library, it's up to you to process the ajax requests in your parent component.
Since Vue.js does not ship with ajax functionality as part of the core library, it's up to you to
process the ajax requests in your parent component.
I recommend using [axios](https://github.com/axios/axios) for creating your applications HTTP layer,
or [`fetch()`](https://github.com/github/fetch) for simple requests.
## Example
The [codepen example](https://codepen.io/sagalbot/pen/POMeOX) wraps up all the above concepts and
searches GitHub repositories. It also uses scoped slots to add some custom templating.
<CodePen url="POMeOX" height="400"/>
+3 -4
View File
@@ -2,9 +2,8 @@
Install with yarn:
```bash
yarn add vue-select
```
or, using NPM:
```
# or, using NPM
npm install vue-select
```
@@ -23,7 +22,7 @@ The component itself does not include any CSS. You'll need to include it separat
import 'vue-select/dist/vue-select.css';
```
You can also import the scss yourself for complete control of the component styles:
Alternatively, you can import the scss for complete control of the component styles:
```scss
@import "vue-select/src/scss/vue-select.scss";
-2
View File
@@ -1,5 +1,3 @@
# Dropdown Options
## Options Prop
`vue-select` accepts arrays of primitive values or objects to use as options through the `options` prop: