快速概览
应用程序中的Owl组件用于定义一个(动态的)组件树。
State: 状态。每个组件都可以管理自己的本地状态。 这是一个简单的 ES6 类,没有特殊规则:
class Counter extends Component {
static template = xml`
<button t-on-click="increment">
Click Me! [<t t-esc="state.value"/>]
</button>`;
state = { value: 0 };
increment() {
this.state.value++;
this.render();
}
}
上面的示例显示了一个具有本地状态的组件。 请注意,由于 state 对象没有什么神奇之处,所以每当我们更新它时,我们都需要手动调用 render 函数。这很快就会变得烦人(如果我们做得太多,效率就会降低)。有一个更好的方法:使用 useState