![]() |
In Vue.JS, the attribute binding allows us to properly manipulate the HTML elements that are based on the Vue Data properties and the expressions. We can bind these attributes using 2 different methods as listed below: Table of Content Approach 1: Using v-bindIn this approach, we use the v-bind directive to bind attributes in Vue.js. We will dynamically bind the src attribute of an image element to the imageUrl data property. By this, users can input the image URL, which will be rendered and displayed on the UI screen. Syntax:<element v-bind="{ attribute: expression }"></element> Example: Below is the implementation of the v-bind approach to bind attributes in VueJS.
Output:Approach 2: Using shortHandIn this apporach, we are performing binding of attributes using the shorthand as :Style to dyncmically change the background color of the button. Syntax:<element :attribute="expression"></element> Example: The below code example implements the shorthand approach to bind attributes in VueJS.
Output:![]() Example 2 Output | How to Bind Attributes in VueJS ? |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |