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 . count } /> } ,
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,36 @@ 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!" , 'parent' )
39- // ...
45+ shouldComponentUpdate ( propName , oldValue , newValue ) {
46+ if ( propName === 'innerCount' ) {
47+ console . log ( propName , oldValue , newValue )
48+ return newValue <= 10 || newValue >= 20 ;
49+ }
50+
51+ return true ;
4052 }
4153
54+ componentDidUpdate ( ) {
55+ console . log ( "parent dom updated!" )
56+ }
57+
58+ // componentDidMount() {
59+ // console.log("parent dom loaded!")
60+ // }
61+
4262 render ( ) {
4363 return (
4464 < >
@@ -56,7 +76,7 @@ class MyComponent extends QuarkElement {
5676 < h1 > { this . text } Quarkc</ h1 >
5777
5878 < div className = "card" >
59- < button onClick = { this . add } > count is: { this . count } </ button >
79+ < button onClick = { this . add } > count is: { this . resolvedCount } </ button >
6080 </ div >
6181 </ div >
6282 < ul >
0 commit comments