Reputation: 134
how can i load Javascripts files in Vue js components ? (Best way)
Upvotes: 1
Views: 59
Reputation: 1160
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>
Upvotes: 2