Skip to content

Commit

Permalink
docs: add info regarding special variables [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Mar 2, 2024
1 parent 981f5f0 commit 76ab73a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ When re-assignment happens in dynamic attributes, it will not trigger a re-rende
<!-- the re-assignment of firstName will not trigger DOM updates -->
```

### Special Variables

There are special variables that you can use inside dynamic attributes and events:

- `this` - the current element
- `$` - equal to the `document.querySelector`.

## Dynamic Attributes

Besides `:value`, `:class`, and `:text`, you can also make **any** attribute dynamic by renaming it from `attribute` to `:attribute`. Values set to dynamic attributes are evaluated as JavaScript:
Expand All @@ -99,10 +106,6 @@ Besides `:value`, `:class`, and `:text`, you can also make **any** attribute dyn
</button>
```

Special variables available in dynamic attributes:

- `this` - the current element

## Classes

You can make your class names reactive by using the `:class` attribute:
Expand Down Expand Up @@ -160,10 +163,11 @@ To set multiple reactive classes, you can use the `:class` attribute:

You can create, use, and update state variables inside DOM events.

Special variables are available in events:
In events, you can get the current event using the `event` variable:

- `event` - the event object
- `this` - the current element
```html
<button :click="console.log(event)">Click Me</button>
```

### Native Events

Expand Down

0 comments on commit 76ab73a

Please sign in to comment.