A simple and effective way to solve this, it’s by adding your external script into the vue mounted() of your component. I will illustrate you with the Google Recaptcha script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <template> .... your HTML </template> <script> export default { data: () => ({ ......data of your component }), mounted() { let recaptchaScript = document.createElement('script') recaptchaScript.setAttribute('src', 'https://www.google.com/recaptcha/api.js') document.head.appendChild(recaptchaScript) }, methods: { ......methods of your component } } </script> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.