1

I am trying to add external js file in vue app.vue. But it's not working. I followed this as adding external style sheet. Also want to include in a component for another js file. I am beginner in vue js. How can I include this. Thanks in advance . I am using vue cli

App.vue

  <template>
    <div id="app">
       <router-view/>
    </div>
  </template>

 <script>
    @import './assets/plugins/bootstrap/js/popper.min.js';
    @import './assets/plugins/bootstrap/js/bootstrap.min.js';
    @import './assets/js/jquery.slimscroll.js';
  </script>
1

1 Answer 1

3

One of these

<script src='./assets/plugins/bootstrap/js/popper.min.js'></script>
<script src='./assets/plugins/bootstrap/js/bootstrap.min.js'></script>
<script src='./assets/js/jquery.slimscroll.js'></script>

or

<script>
export default
{
   import './assets/plugins/bootstrap/js/popper.min.js';
   import './assets/plugins/bootstrap/js/bootstrap.min.js';
   import './assets/js/jquery.slimscroll.js';
}
</script>

But it would be better if you import scripts like these into your public/index.html file.

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

6 Comments

Thanks for reply. AS per your instruction I add those in public/index.html . Like <link href='@/assets/plugins/bootstrap/css/bootstrap.min.css' rel="stylesheet"> and <script src='./assets/plugins/bootstrap/js/popper.min.js'></script> . but it's not working
You should check whether these are the right paths to use - the paths in public/index.html are relative to this file at the time of its deployment while the paths in your ES6 JavaScript module are relative to that file (probably inside src folder)
I also tried with that. <link href='src/assets/styles/style.css' rel="stylesheet"> but not working. folder structure is src/assets/styles/style.css and src/assets/js/popper.min.js
How can I access files from src/... because my index file is in public folder.
You have to put such files inside the public folder.
|

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.