Categories
Vue Answers

How to set static image src in Vue.js template with JavaScript?

Spread the love

Sometimes, we want to set static image src in Vue.js template with JavaScript.

In this article, we’ll look at how to set static image src in Vue.js template with JavaScript.

How to set static image src in Vue.js template with JavaScript?

To set static image src in Vue.js template with JavaScript, we set the path relative to the src folder.

For instance, we write

<template>
  <img src="/static/img/clear.gif" />
</template>

to add an img element with src set to a path relative to the src folder to load the image.

Conclusion

To set static image src in Vue.js template with JavaScript, we set the path relative to the src folder.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *