在哪里初始化 Stencil 中的变量
Where to initialize variables in Stencil
我刚开始使用 Stencil,我想知道什么是初始化变量的好习惯。
在我看来,我有 3 种可能性:
1) @State() private page: Boolean = true;
2)
constructor() {
this.page = true
}
3)
componentWillLoad() {
this.page = true;
}
最好的方法是什么?
根据 Stencil Style Guide 如果可以,您应该在声明时初始化 @State
变量:
/**
* 3. State() variables
* Inlined decorator, alphabetical order.
*/
@State() isValidated: boolean;
@State() status = 0;
我刚开始使用 Stencil,我想知道什么是初始化变量的好习惯。 在我看来,我有 3 种可能性:
1) @State() private page: Boolean = true;
2)
constructor() {
this.page = true
}
3)
componentWillLoad() {
this.page = true;
}
最好的方法是什么?
根据 Stencil Style Guide 如果可以,您应该在声明时初始化 @State
变量:
/**
* 3. State() variables
* Inlined decorator, alphabetical order.
*/
@State() isValidated: boolean;
@State() status = 0;