How to import and use image in a Vue single file component?

As simple as: <template> <div id=”app”> <img src=”./assets/logo.png”> </div> </template> <script> export default { } </script> <style lang=”css”> </style> Taken from the project generated by vue cli. If you want to use your image as a module, do not forget to bind data to your Vuejs component: <template> <div id=”app”> <img :src=”image”/> </div> </template> <script> … Read more

How to solve ‘Redirect has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header’?

In addition to what awd mentioned about getting the person responsible for the server to reconfigure (an impractical solution for local development) I use a change-origin chrome plugin like this: Moesif Orign & CORS Changer You can make your local dev server (ex: localhost:8080) to appear to be coming from 172.16.1.157:8002 or any other domain.

Vuejs Error: The client-side rendered virtual DOM tree is not matching server-rendered

Partial answer: with Chrome DevTools, you can localize the issue and see exactly what element caused the issue. Do the following (I did that with Nuxt 5.6.0 and Chrome 64.0.3282.186) Show DevTools in Chrome (F12) Load the page that causes “the client-side rendered virtual DOM tree…” warning. Scroll to the warning in DevTools console. Click … Read more

How to add external JS scripts to VueJS Components?

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: <template> …. your HTML </template> <script> export default { data: () => ({ ……data of your component }), mounted() { let recaptchaScript = document.createElement(‘script’) recaptchaScript.setAttribute(‘src’, … Read more