Categories
Vue Answers

How to reference static assets within Vue.js and JavaScript?

Spread the love

Sometimes, we want to reference static assets within Vue.js and JavaScript.

In this article, we’ll look at how to reference static assets within Vue.js and JavaScript.

How to reference static assets within Vue.js and JavaScript?

To reference static assets within Vue.js and JavaScript, we can use @/ as the alias of the src/ folder.

For instance, we write

<img src="@/assets/images/home.png"/>

to set the src attribute of the img element to @/assets/images/home.png which is the same as src/assets/images/home.png in the Vue project folder.

Conclusion

To reference static assets within Vue.js and JavaScript, we can use @/ as the alias of 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 *