7

I'm building my first project using vue-cli and webpack and I'm not sure how to properly use an external JavaScript library to my project.

I want to add the Intro.js library which simply requires me to import the intro.js, add some tags to some HTML elements, and call the introJs().start() function.

I've installed the library with npm install introj.js --save

I've imported the library by adding import introJS from 'intro.js' into my <script> section of my App.vue file.

I've checked the compiled app.js file and I know introJS is being compiled so everything is good there.

My question is, where do I put introJs().start()? I tried putting it in the mounted() function of the App.vue file but that doesn't work.

Additional Info: When I try to run introJS().start() from the mounted () method in App.vue I receive this error: Error in mounted hook: "TypeError: __WEBPACK_IMPORTED_MODULE_7_intro_js___default(...) is not a function"

8
  • What about putting it in main.js before new Vue({...}) ? Commented Jul 16, 2017 at 20:08
  • I tried that but I still get the error above stating that start is not a function. Commented Jul 16, 2017 at 20:12
  • 2
    Try this introJS.introJs().start() Commented Jul 16, 2017 at 20:20
  • That did it! I knew it was going to be something simple. How did you figure it out? Why do I reference it like that? Commented Jul 16, 2017 at 20:29
  • Cool. after importing introJS. I stored a global reference to it window.introJS = introJS. Then inspected it in the console. Commented Jul 16, 2017 at 20:32

1 Answer 1

7

This should work:

const { introJS } = require('intro.js')
introJS().start()
Sign up to request clarification or add additional context in comments.

1 Comment

For me it says that Cannot read properties of undefined (reading 'start'). Do I have to use it with older version of intro.js like 2.9.3 or what?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.