Skip to content

Commit

Permalink
Added example of using methods to docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
michielvandergeest committed Mar 13, 2024
1 parent 57d2d24 commit 50ce597
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/components/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,35 @@ If you notice that you're duplicating logic in these different places, or if you
You can reference your Component's methods in the template by using a `$`-sign (for example in the `@loaded`-attribute when your element has a `src` attribute).

In the javascript code of a Component you can reference methods directly on the `this`-scope (i.e. `this.getData()`). Similar as with `internal` state and `props`, there is no need to prefix with `methods`, for easy access.

```js
export default Blits('Carousel', {
template: `
<Element>
<!-- .... -->
</Element>
`,
state() {
return {
items: [],
page: 0
}
},
hooks: {
ready() {
this.fetchData()
}
},
input: {
down() {
this.page++
this.fetchData()
}
},
methods: {
async fetchData() {
this.items = await API.get(['movies', 'tvshows', 'documentaries'], this.page)
},
}
})
```

0 comments on commit 50ce597

Please sign in to comment.