Skip to content

Instantly share code, notes, and snippets.

@MakeHoney
Last active April 17, 2019 09:05
Show Gist options
  • Save MakeHoney/daf4c658f47a47b41fe0206d07464d02 to your computer and use it in GitHub Desktop.
Save MakeHoney/daf4c658f47a47b41fe0206d07464d02 to your computer and use it in GitHub Desktop.
버튼을 누르면 다음 우편번호(주소) API가 팝업되는 컴포넌트
<template>
<div>
<button @click="popButton">주소</button>
</div>
</template>
<script>
export default {
data: _ => ({
daumPostCode: null
}),
async mounted() {
await this.loadDaumPostcode()
this.daumPostCode = new daum.Postcode({
oncomplete: data => {
console.log(data)
}
});
},
methods: {
popButton() {
this.daumPostCode.open()
},
loadDaumPostcode() {
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.setAttribute('src', 'http://dmaps.daum.net/map_js_init/postcode.v2.js?autoload=false')
script.onload = () => daum.postcode.load(() => resolve())
script.onerror = reject
document.head.appendChild(script)
})
},
}
}
</script>
<style scoped>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment