Adding Awesomplete to Vue Components
by endpointpatrick
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.4/awesomplete.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.4/awesomplete.base.min.css">
<div id="app">
<h2>Search by Name</h2>
<p>
<em>
Options: {{ names.join(', ') }}
</em>
</p>
<form>
<input
id="name-input"
placeholder="Enter a name"
type="text"
>
</form>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
em {
font-style: italic;
}
form {
margin-top: 20px;
}
Vue
new Vue({
el: "#app",
data () {
return {
names: [
'Colin Creevey',
'Seamus Finnigan',
'Lee Jordan'
]
}
},
mounted () {
let input = document.getElementById('name-input')
new Awesomplete(input, { minChars: 3, list: this.names })
input.addEventListener('awesomplete-select', (e) => {
alert(`Selected ${e.text.value}`)
})
}
})