javascript - Where to initialize variables in Stencil
问题描述
I have just started Stencil, and I was wondering what was a good practise for initizializing variables. As I see it, I have 3 possibilities:
1) @State() private page: Boolean = true;
2)
constructor() {
this.page = true
}
3)
componentWillLoad() {
this.page = true;
}
What's the best way to do it ?
解决方案
根据模板样式指南,如果可以的话,您应该在声明时初始化@State
变量:
/**
* 3. State() variables
* Inlined decorator, alphabetical order.
*/
@State() isValidated: boolean;
@State() status = 0;
推荐阅读
- python - 如何在使用 PIL 保存 png 时保留 RGB 颜色?
- c# - Sql server 未在 Visual Studio 中加载
- react-native - 反应导航标题总是显示
- javascript - 如何在不刷新页面的情况下查看更新列表
- javascript - 无法使用 webpack DefinePlugin 从 React 应用程序中的 dockerfile 访问环境变量
- spring-boot - 从 credhub 加载属性并在 PCF 清单中使用
- gitlab - 如何克隆到 gitlab-runner 用户的主目录?
- python-3.x - 有效地计算数组最后一维的点积
- javascript - 如何从 JSON 对象中获取值
- github - 如何将公共 ssh 密钥添加到私人仓库?