示例工程 30-web-components-types

30-web-components-types/04-observed-attributes/README.md

markdown · 0.6 KB

运行:30 · observed-attributes

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

# 04 · observed-attributes
 
**演示**:`static observedAttributes = ['name']` + `attributeChangedCallback` 实现属性反射。
**运行**:在 `tutorials/typescript` 下执行 `npm run build`,再执行 `npm run serve`,打开
`http://localhost:8080/examples/30-web-components-types/04-observed-attributes/`;开 Console。
**预期控制台输出**:
```text
Hi Ada
```
**类型检查**:`node node_modules/typescript/bin/tsc -p examples/30-web-components-types/04-observed-attributes/tsconfig.types.json`
**注意**:`attributeChangedCallback` 可能在 `connectedCallback` 之前触发;初始化逻辑要幂等。