最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding the Intro.JS library to a Vue-CliWebpack project - Stack Overflow

programmeradmin3浏览0评论

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 piled app.js file and I know introJS is being piled 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"

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 piled app.js file and I know introJS is being piled 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"

Share Improve this question edited Jan 25, 2018 at 21:49 Ikbel 7,8513 gold badges36 silver badges46 bronze badges asked Jul 16, 2017 at 19:42 Daniel DDaniel D 99810 silver badges18 bronze badges 8
  • What about putting it in main.js before new Vue({...}) ? – Ikbel Commented Jul 16, 2017 at 20:08
  • I tried that but I still get the error above stating that start is not a function. – Daniel D Commented Jul 16, 2017 at 20:12
  • 2 Try this introJS.introJs().start() – Ikbel 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? – Daniel D 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. – Ikbel Commented Jul 16, 2017 at 20:32
 |  Show 3 more ments

1 Answer 1

Reset to default 7

This should work:

const { introJS } = require('intro.js')
introJS().start()
发布评论

评论列表(0)

  1. 暂无评论