diff --git a/docs/components/methods.md b/docs/components/methods.md index e1bd84ef..3662b5a3 100644 --- a/docs/components/methods.md +++ b/docs/components/methods.md @@ -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: ` + + + + `, + 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) + }, + } +}) +```