Last active
November 11, 2021 16:54
-
-
Save SidneyAllen/8df9c057573fcd820ee65e05ea479ced to your computer and use it in GitHub Desktop.
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
<script> | |
import { ref } from "vue"; | |
import Autocomplete from 'vue3-autocomplete' | |
import useAddressSuggestions from "./useAddressSuggestions"; | |
export default { | |
name: "App", | |
components: { | |
Autocomplete | |
}, | |
setup () { | |
const address = ref() | |
const city = ref() | |
const state = ref() | |
const zip = ref() | |
const suggestions = ref([]) | |
// insert selected function | |
function selected(suggestion) { | |
address.value.setText(suggestion.data.primary_line) | |
city.value = suggestion.data.city | |
state.value = suggestion.data.state | |
zip.value = suggestion.data.zip_code | |
suggestions.value = [] | |
} | |
const { getSuggestions } = useAddressSuggestions() | |
async function onAddressInput (val) { | |
suggestions.value = await getSuggestions(val) | |
} | |
return { | |
address, | |
city, | |
state, | |
zip, | |
onAddressInput, | |
suggestions, | |
getSuggestions, | |
// insert selected prop | |
selected | |
} | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment