Last active
July 7, 2018 20:34
-
-
Save jonathanharrell/f83516b423f74105434b1bd5ff346e15 to your computer and use it in GitHub Desktop.
Vue SearchSelect Component (with scoped slots)
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
Vue.component('search-select', { | |
props: [ | |
'options', | |
'filterMethod' | |
], | |
data () { | |
return { | |
query: '' | |
} | |
}, | |
computed: { | |
results () { | |
return this.filterMethod(this.options, this.query) | |
} | |
}, | |
methods: { | |
setQuery (event) { | |
this.query = event.target.value | |
} | |
}, | |
render () { | |
return this.$scopedSlots.default({ | |
results: this.results, | |
searchList: (event) => { | |
this.setQuery(event) | |
} | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment