2
我試圖抽象Google Places自動完成輸入組件,以便多次使用它。範圍內的組件衝突
但是,當我實例化超過1個以下組件時,數據和方法會重疊。 (同place
得到記錄)
<template>
<input :ref="inputRef" type="text">
</template>
<script>
var autocompleteInput
export default {
props: ['inputRef'],
methods: {
fetchAddress() {
var place = autocompleteInput.getPlace();
console.log(place)
}
},
mounted() {
autocompleteInput = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(this.$refs[this.inputRef]),
{types: ['address']});
autocompleteInput.addListener('place_changed', this.fetchAddress);
console.log(this.$refs[this.inputRef])
}
}
</script>
我的猜測是,var autocompleteInput
是問題,因爲它似乎是超出範圍。
但是我不知道如何將其範圍縮小。
我該如何解決這個問題?
這樣做。謝謝。基礎的力量。 – softcode