Skip to content

Instantly share code, notes, and snippets.

@system123
Created July 1, 2018 16:51
Show Gist options
  • Save system123/6e44b59db7214bebc7fd9afa929ab6c0 to your computer and use it in GitHub Desktop.
Save system123/6e44b59db7214bebc7fd9afa929ab6c0 to your computer and use it in GitHub Desktop.
Searchbar
<template>
<div id="searchbar">
<v-text-field
flat
solo-inverted
append-icon="search"
label="Find Location"
class="hidden-sm-and-down"
v-model='defaultInput'
></v-text-field>
</div>
</template>
<script>
import MglGeocoderControl from 'vue-mapbox-geocoder'
import Vue from 'vue'
export default {
name: "Searchbar",
data() {
return {
accessToken: '<my token>',
defaultInput: ''
}
},
created() {
var ComponentClass = Vue.extend(MglGeocoderControl)
this.$geocoder = new ComponentClass({
propsData: { accessToken: this.accessToken, input: this.defaultInput }
})
this.$geocoder.$on('results', this.handleSearch)
this.$geocoder.created()
},
methods: {
handleSearch(event) {
console.log(event)
}
},
watch: {
defaultInput (next, prev) {
this.handleSearch(this.$geocoder.control.query(next))
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment