Created
April 17, 2019 06:48
-
-
Save MakeHoney/146fb325ace0e3b93bb2adecf2b84536 to your computer and use it in GitHub Desktop.
CDN을 전역이 아닌, 지역적으로 (특정 컴포넌트에서만) 불러오는 코드.
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> | |
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
loadDaumPostcode 메소드 실행 후 load가 완료되면 window 아래 (DOM)에 daum 객체가 append된다.
따라서 해당 컴포넌트에서는 전역으로 daum 객체를 사용할 수 있다.