how can i load Javascripts files in Vue js components ? (Best way)
-
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
Add a comment
|
1 Answer
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>