Guide: Class and Style Bindings Flashcards

1
Q

What is the reasoning behind the special enhancements for class and style?

A
  • Meddling with string concatenation is annoying, error-prone, and not structured
  • Using v-bind with the class and style attributes enables us to have expressions evaluate to objects or arrays, along with strings
  • Therefore, strings, objects, and arrays are valid values for class and style
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe the various ways you can use object syntax with v-bind:class.

A
  • By passing an object literal
    • `

`

  • By using it with the plain class attribute
    • `

`

  • By passing a reference to an object
    • `

`

* define `classObj` in `data`, or from `props` * By binding to a computed property which returns an object
* Super powerful and common
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe the ways to use array syntax.

A
  • String literals in the array
    • `

`

  • Bind to properties
    • `

`

  • Toggling an individual class conditionally with a ternary expression
    • `

`

  • Use object syntax inside of array syntax
    • `

`

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when using the class attribute on a custom component?

A

Those classes will be added to the component’s root element. Existing classes on this element will not be overwritten.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe how to properly type style property names with binded style attributes.

A
  • Use either camelCase or kebab-case with quotes
    • `
      `
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the best way to use object syntax with the style attribute.

A

To either bind to a style object, or a computed property, so that the template doesn’t get too bloated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe how to use the array syntax for the style attribute

A
  • Allows you to bind multiple style objects to the same element
    • `
      `
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What special operation happens when using :style?

A

Vue automatically detects and adds appropriate prefixes that are required for specific browsers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly