Check out a free preview of the full Introduction to Vue 3 course

The "v-bind" Lesson is part of the full, Introduction to Vue 3 course featured in this preview video. Here's what you'd learn in this lesson:

Sarah defines v-bind as a directive that can be used for style binding, class binding, or for creating dynamic props, and why v-bind is one of the most useful directives.

Preview
Close

Transcript from the "v-bind" Lesson

[00:00:00]
>> V-BIND or colon I know I said I love V model the most, but I also love V-BIND the most. I like both of them. Okay, so, V-BIND or this colon that's a shortcut, we have a couple of shortcuts in Vue because there are some directives you'll use again and again and again.

[00:00:16]
And it's a little bit more legible to just use the colon instead of writing V-BIND, V-BIND, V-BIND. So it's one of the most useful directives. That's part of the reason why it has a shortcut. We can use it for so many things. We can use it for class and style bindings, dynamic props, etc.

[00:00:33]
So I'll show you some examples. So, here instead of the button not being on the page, what we have is this V-BIND of a state of a class. So we're basically saying, if talk and then we have a ternary operator. If tacos is true, add an active class otherwise don't.

[00:00:52]
So I can say like our past or here and what you can see is that we now have that class appended. So if we looking inside here we see this button .active. What we have is tacos as an empty string. And we said, okay, add the active class or active class in this case was active and that's how it knows to kind of toggle back and forth between those classes.

[00:01:20]
Here's an example that's like, this is a very common use case making weird Tron things. No, I'm just kidding. So this is a style binding that we're changing perspective origin based on your mouse movements. So, if I move my mouse around, I have this event at mouse move and I'm able to bind x&y coordinates.

[00:01:42]
To this style, and that's how I'm doing this. That's all that it takes to make something move around in space, which is really cool. So that's that V-BIND style right here.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now