State management in Marko.js components can be done using the state object. Here’s an example:
<template>
<div>
<p>Count: ${state.count}</p>
<button on-click('increment')>Increment</button>
</div>
</template>
<script>
module.exports = class {
onCreate() {
this.state = { count: 0 };
}
increment() {
this.state.count++;
}
};
</script>
In this example, the state object is used to keep track of a count, and the increment method updates this state.