Skip to content

Instantly share code, notes, and snippets.

@MakeHoney
Created April 17, 2019 06:48
Show Gist options
  • Save MakeHoney/146fb325ace0e3b93bb2adecf2b84536 to your computer and use it in GitHub Desktop.
Save MakeHoney/146fb325ace0e3b93bb2adecf2b84536 to your computer and use it in GitHub Desktop.
CDN을 전역이 아닌, 지역적으로 (특정 컴포넌트에서만) 불러오는 코드.
<template>
<div>
<h1> snippet code </h1>
</div>
</template>
<script>
export default {
async mounted() {
await this.loadDaumPostcode()
daum.postcode.load(function(){
new daum.Postcode({
oncomplete: function(data) {
console.log(data)
}
}).open();
});
},
methods: {
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 = resolve
script.onerror = reject
document.head.appendChild(script)
})
},
}
}
</script>
<style scoped>
</style>
@MakeHoney
Copy link
Author

MakeHoney commented Apr 17, 2019

loadDaumPostcode 메소드 실행 후 load가 완료되면 window 아래 (DOM)에 daum 객체가 append된다.
따라서 해당 컴포넌트에서는 전역으로 daum 객체를 사용할 수 있다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment