Adding Intro.JS library to Vue-Cli / Webpack project

I am creating my first project using vue-cli and webpack , and I'm not sure how to use the external JavaScript library for my project correctly.

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

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

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

I checked the compiled file app.jsand I know that introJS will compile, so everything is fine there.

My question is: where can I put introJs().start()? I tried putting it in a mounted()file function App.vue, but that does not work.

Additional info: When I try to run introJs().start()from a method mounted ()in App.vue, I get this error:Error in mounted hook: "TypeError: __WEBPACK_IMPORTED_MODULE_7_intro_js___default(...) is not a function"

+4
source share
1 answer

This should work:

var introJS = require('intro.js').introJs
introJS().start()
+6
source

Source: https://habr.com/ru/post/1681571/


All Articles