Last active
April 17, 2019 09:05
-
-
Save MakeHoney/daf4c658f47a47b41fe0206d07464d02 to your computer and use it in GitHub Desktop.
버튼을 누르면 다음 우편번호(주소) API가 팝업되는 컴포넌트
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
<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