Skip to content

Instantly share code, notes, and snippets.

@srph
Last active December 30, 2017 15:08
Show Gist options
  • Select an option

  • Save srph/665af67d03c3194e05e5db1a6c0b8ff1 to your computer and use it in GitHub Desktop.

Select an option

Save srph/665af67d03c3194e05e5db1a6c0b8ff1 to your computer and use it in GitHub Desktop.
<template>
<div>
<slot></slot>
</div>
</template>
<script>
export default {
name: 'autocomplete',
provide() {
return {
autocomplete: {
setInput: (input) => {
this.input = input
}
}
}
},
data() {
return {
value: '',
input: null
}
}
methods: {
onInput() {
// Use this.input here to do stuff
}
},
// Other properties... redacted for example purposes
}
</script>
<template>
<input v-bind="$props" v-on="$listeners" ref="input">
</template>
<script>
export default {
name: 'autocomplete-input',
inject: ['autocomplete'],
mounted() {
this.autocomplete.setInput(this.$refs.input)
},
// Other properties... redacted for example purposes
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment