A
A
Andrey Vasilev2020-06-26 13:32:40
Vue.js
Andrey Vasilev, 2020-06-26 13:32:40

How to include a script only in a specific Vue component?

Hello.
How can I connect the script to the user only when a certain component is displayed? (vue route)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-06-26
@Nolis

https://habr.com/ru/company/mailru/blog/350962/

M
Michael, 2020-06-27
@Nolan81

Drop the some.js script into the assets folder.
And in the created hook of this page component, write:

let someScript = document.createElement('script')
someScript.setAttribute('src', 'some.js')
document.head.appendChild(someScript);

It will be called every time when going to the route

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question