1- import { QuarkElement , property , customElement } from "quarkc"
1+ import { QuarkElement , property , customElement , state , computed } from "quarkc"
22import { Router } from "quark-router"
33import "./pages/home"
44import "./pages/sub"
@@ -14,7 +14,7 @@ declare global {
1414@customElement ( { tag : "my-component" , style } )
1515class MyComponent extends QuarkElement {
1616 private _routes = new Router ( this , [
17- { path : '/' , render : ( ) => < home-component /> } ,
17+ { path : '/' , render : ( ) => < home-component count = { this . resolvedCount } /> } ,
1818 { path : '/sub/:id' , render : ( { id} ) => < sub-component id = { id } /> } ,
1919 { path : '/child/*' , render : ( ) => < child-component /> } ,
2020 { path : '/child' , render : ( ) => < child-component /> } ,
@@ -29,16 +29,35 @@ class MyComponent extends QuarkElement {
2929 @property ( { type : String } )
3030 text
3131
32+ @state ( )
33+ innerCount = 0 ;
34+
35+ @computed ( )
36+ get resolvedCount ( ) {
37+ return this . count + this . innerCount ;
38+ }
39+
3240 add = ( ) => {
3341 // 内部事件
34- this . count += 1
42+ this . innerCount += 1
3543 } ;
3644
37- componentDidMount ( ) {
38- console . log ( "dom loaded!" )
39- // ...
45+ shouldComponentUpdate ( propName , oldValue , newValue ) {
46+ if ( propName === 'innerCount' ) {
47+ return newValue <= 10 ;
48+ }
49+
50+ return true ;
4051 }
4152
53+ componentDidUpdate ( ) {
54+ console . log ( "parent dom updated!" )
55+ }
56+
57+ // componentDidMount() {
58+ // console.log("parent dom loaded!")
59+ // }
60+
4261 render ( ) {
4362 return (
4463 < >
@@ -56,7 +75,7 @@ class MyComponent extends QuarkElement {
5675 < h1 > { this . text } Quarkc</ h1 >
5776
5877 < div className = "card" >
59- < button onClick = { this . add } > count is: { this . count } </ button >
78+ < button onClick = { this . add } > count is: { this . resolvedCount } </ button >
6079 </ div >
6180 </ div >
6281 < ul >
0 commit comments