![]() |
In VueJS, the background images can be set from different types of properties like data property, computed property, or directly from an image source. In this article, we will see the different approaches to bind the background image in VueJS as listed below: Table of Content Using Inline StyleIn this approach, we directly bind the background image by specifying inline styles using the style attribute. Syntax:<div :style="{ backgroundImage: 'url(\'your-image-url.jpg\')' }"></div>
Example: The below code example will explain the use of the inline style binding to bind the background image HTML
Output: Using CSS ClassesIn this approach we use CSS clases to bind background image, if you have styles for different background images then this approach helps in bind them dynamically. Syntax:<div :class="{ 'background-class-1': condition, 'background-class-2': !condition }"></div>
Example: The below example explains the use of the classes to bind the styles using VueJS. HTML
Output: |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |