how can i load Javascripts files in Vue js components ? (Best way)
Asked
Active
Viewed 47 times
1
-
best way? so, what ways have you tried? – Jaromanda X May 10 '20 at 06:49
-
Does this answer your question? [How to add external JS scripts to VueJS Components](https://stackoverflow.com/questions/45047126/how-to-add-external-js-scripts-to-vuejs-components) – A. El-zahaby May 10 '20 at 06:55
1 Answers
2
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>

A. El-zahaby
- 1,130
- 11
- 32