0

I have an animation js file, that I'm trying to use on a specific vue component. I tried to use import, required and mounted(), but none of that worked so far

 <template>
 <div class="home">
<audio controls="controls" src="../assets/raindrops-in-the-ocean.mp3"></audio>
<canvas id="canvas"></canvas>
 </div>
</template>
   <script>
    require('../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>
3
  • What does your build process look like? Commented Jan 2, 2020 at 1:19
  • Do you mean npm run build? Commented Jan 2, 2020 at 1:56
  • Good example here: stackoverflow.com/a/56639128/2162226 Commented Dec 30, 2020 at 18:50

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.