Created
May 12, 2022 20:56
-
-
Save lobot/c41f2f96d538e44c12d3886523b20085 to your computer and use it in GitHub Desktop.
autocomplete with verification
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 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