Sometimes, we want to fix Vue.js dynamic images not working with JavaScript.
In this article, we’ll look at how to fix Vue.js dynamic images not working with JavaScript.
How to fix Vue.js dynamic images not working with JavaScript?
To fix Vue.js dynamic images not working with JavaScript, we use the require
function.
For instance, we write
<img :src="require(`@/images/${name}.png`)" alt class="icon" />
in our template.
We set the src
prop to the path returned by require
to render the image we call require
with.
Conclusion
To fix Vue.js dynamic images not working with JavaScript, we use the require
function.