2

I would like to include in a vuejs component this jquery plugin : http://jvenn.toulouse.inra.fr/app/js/jvenn.min.js.

to do so, I added these lines

mounted () {
  const jvenn = document.createElement('script')
  jvenn.setAttribute(
    'src',
    'http://jvenn.toulouse.inra.fr/app/js/jvenn.min.js'
  )
  jvenn.async = true
  document.head.appendChild(jvenn)
}

it works fine, but I'd like to have a local copy of this script in case this file will no longer be online. I tryed to add it in my assets directory, and to change http://jvenn.toulouse.inra.fr/app/js/jvenn.min.js by /static/js/jvenn.min.js without success.

Any idea ?

5
  • you don't need first / Commented May 21, 2021 at 9:52
  • "without success" - Have you done any debugging? Are you using the browser console and network pane? Commented May 21, 2021 at 9:52
  • static is not a prefixed directory. It is mapped directly into the root at both run and compile time. therefore, /js/jvenn.min.js will work. Commented May 21, 2021 at 9:57
  • @FlYiNGPoTAToChiP and @Ohgodwhy it returns the error $(...).jvenn is not a function Commented May 21, 2021 at 10:05
  • Why not keep it global in your index.html included? Commented May 21, 2021 at 15:38

2 Answers 2

2

Assuming a Vue CLI scaffolded project, put the third party script in the public folder to make it a static asset:

public
└─js
|  └─jvenn.min.js
└─index.html

Then edit public/index.html to import the script:

<body>
  <script src="<%= BASE_URL %>js/jvenn.min.js"></script>
</body>

The <%= BASE_URL %> prefix in src is important if the project's base URL is configured.

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

Comments

0

if

js
└─jvenn.min.js
index.html

then it will be just js/jvenn.min.js

1 Comment

I should have clearer mentioned, I'm using vuejs, I added the info in the title

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.