Last active
May 16, 2018 18:16
-
-
Save heisenberg-lgbt-ulanbator/368aba07c11869bbca28c421ef43f095 to your computer and use it in GitHub Desktop.
Yandex suggest view vuejs2 component.
This file contains hidden or 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
<script> | |
export default { | |
props: ['value', 'city'], | |
template: '<input type="text" \ | |
id="address-autocomplete"\ | |
ref="input" \ | |
v-bind:value="value" \ | |
v-on:input="$emit(\'input\', $event.target.value)"/>', | |
mounted: function () { | |
ymaps.ready(this.init); | |
}, | |
methods: { | |
init(){ | |
let _this = this, | |
suggestView = new ymaps.SuggestView('address-autocomplete', { | |
provider: { | |
suggest:(function(request, options){ | |
return ymaps.suggest(_this.city+", " + request); | |
})} | |
}); | |
suggestView.events.add(["select"], function (event) { | |
let address = event.get('item').value, | |
pattern = new RegExp('^.+'+_this.city+', '); | |
_this.$emit('input', address.replace(pattern, '')); | |
}) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment