-
-
Save system123/6e44b59db7214bebc7fd9afa929ab6c0 to your computer and use it in GitHub Desktop.
Searchbar
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
<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