Skip to content

Instantly share code, notes, and snippets.

@lobot
Created May 12, 2022 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lobot/c41f2f96d538e44c12d3886523b20085 to your computer and use it in GitHub Desktop.
Save lobot/c41f2f96d538e44c12d3886523b20085 to your computer and use it in GitHub Desktop.
autocomplete with verification
<script setup>
import AddressAutocomplete, { verify } from '@lob/vue-address-autocomplete'
import '@lob/vue-address-autocomplete/dist/styles.css'
</script>
<template>
<main>
<AddressAutocomplete
:apiKey="lobApiKey"
@onInput="handleInput"
@onSelect="handleSelect"
/>
<button @click="handleSubmit">Verify</button>
<p>
{{verificationResult}}
</p>
</main>
</template>
<script>
export default {
data() {
return {
address: '',
lobApiKey: 'YOUR_LOB_API_KEY',
verificationResult: null
}
},
methods: {
handleInput(userInput) {
this.address = userInput
},
handleSelect(selectedAddress) {
this.address = selectedAddress.value
},
handleSubmit() {
verify(this.lobApiKey, this.address)
.then((result) => {
// Simplify response into something readable to the user
const summary = `This address is ${result.deliverability}`
this.verificationResult = summary
})
.catch((errorData) => this.verificationResult = errorData.message)
}
}
}
</script>
<style scoped>
button {
margin-top: 1em;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment