how can i load Javascripts files in Vue js components ? (Best way)
asked May 10, 2020 at 6:14
Matin Rezaii
1341 gold badge1 silver badge7 bronze badges
-
best way? so, what ways have you tried?Jaromanda X– Jaromanda X2020年05月10日 06:49:02 +00:00Commented May 10, 2020 at 6:49
-
Does this answer your question? How to add external JS scripts to VueJS ComponentsA. El-zahaby– A. El-zahaby2020年05月10日 06:55:44 +00:00Commented May 10, 2020 at 6:55
1 Answer 1
you can just create script element in the mounted method :
<script>
export default {
data: () => ({
// ...data of your component
}),
mounted() {
let script1 = document.createElement('script')
script1.setAttribute('src', 'path/to/file.js')
script1.async = true
document.head.appendChild(script1)
}
}
</script>
answered May 10, 2020 at 6:53
A. El-zahaby
1,17212 silver badges37 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default