0

I have the concept of a homepage (Home.vue) that is based off a template I purchased *includes (css, html file, and custom javascript). Almost all the css has been imported correctly but I can't seem to get the javascript loaded like the template. I believe Vue bundles everything into the app.js maybe?

Here is the Source of structure of the template and the my project.

Template enter image description here

My file enter image description here

4
  • Are you using webpack? Typically you need to import or require the main JS file for that library. Commented Mar 6, 2020 at 5:17
  • Does this answer your question? How to include local script files in Vue - as mentioned in the answer, your scripts should be modules. otherwise import them in your index.html using the script tag. Commented Mar 6, 2020 at 5:22
  • You can import the JavaScript files like import './path-to-js.js'; this is called a side effecting import and the result will be that the these files are loaded with your app and bundled with it for production Commented Mar 6, 2020 at 8:09
  • @rx2347 you are correct sir! One comment though below. Commented Mar 9, 2020 at 4:56

1 Answer 1

0

@rx2347 That works! (But)

What's weird is that the local javascript is jquery / legacy js, so they don't export anything. I don't think the javascript has time to find the elements on the DOM referenced in the legacy code (ex. document.getElementById('asd'))

So that's on me to figure out

Thanks for the help!

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

2 Comments

You'll probably want to look into the vue lifecycle hooks like mounted() and created() for that before running any dom related functions from those scripts: vuejs.org/v2/guide/instance.html#Lifecycle-Diagram
@rx2347 yeah good idea for sure. I think I got it working actually just including them in main js with the import * as myBlabla "blabla.js"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.