1

how can i load Javascripts files in Vue js components ? (Best way)

Matin Rezaii
  • 136
  • 1
  • 1
  • 7

1 Answers1

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