[Vuejs]-How to use locally js files in vue components?

1👍

By using below import statement you can use locally javascript file:

<script>
    import '../assets/raindrops.js';
    
    export default {
        name: 'raindrops-in-the-ocean',
        components: {},
        created() {
            let recaptchaScript = document.createElement('script')
            recaptchaScript.setAttribute('src', '../assets/raindrops.js')
            document.head.appendChild(recaptchaScript)
        },
    } 
</script>

Note: It is recommended to use relative path instead of absolute path for importing any file

Leave a comment