-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
263 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,73 @@ | ||
import '@abraham/reflection' | ||
import { Component, Computed, Hook, Link, Mut, VueComponent } from 'vue3-oop' | ||
import { createApp, watchSyncEffect } from 'vue' | ||
import './theme/app.css' | ||
import { CountService } from './count.service' | ||
import { SizeService } from './size.service' | ||
import { Component, Computed, Hook, Mut, VueComponent, VueService } from 'vue3-oop' | ||
import { createApp } from 'vue' | ||
|
||
class Child extends VueComponent { | ||
render() { | ||
console.log('render') | ||
return ( | ||
<div> | ||
111 | ||
<div>{this.context.slots.default?.()}</div> | ||
</div> | ||
) | ||
const debounce = (delay: number) => { | ||
let timeout: number | undefined | ||
return (track: any, trigger: any) => { | ||
let value: any | ||
return { | ||
get() { | ||
track() | ||
return value | ||
}, | ||
set(newValue: any) { | ||
clearTimeout(timeout) | ||
timeout = window.setTimeout(() => { | ||
value = newValue | ||
trigger() | ||
}, delay) | ||
}, | ||
} | ||
} | ||
} | ||
|
||
@Component() | ||
class CountService extends VueService { | ||
@Mut() count = 1 | ||
} | ||
|
||
class Home extends VueComponent { | ||
constructor(private countService: CountService, private sizeService: SizeService) { | ||
super() | ||
watchSyncEffect(() => this.count > 2) | ||
} | ||
@Mut(debounce(1000)) _count = '' | ||
|
||
@Mut() count = 1 | ||
@Mut() obj = { name: 123 } | ||
|
||
@Computed() | ||
get double() { | ||
return this.count * 2 | ||
return this._count | ||
} | ||
set double(val: string) { | ||
this._count = val.toUpperCase() | ||
} | ||
list = new Array(10).fill(1) | ||
|
||
@Link() aaa: Child[] | ||
|
||
@Hook('Mounted') | ||
mounted() { | ||
console.log(this.aaa) | ||
console.log('mounted') | ||
} | ||
|
||
render() { | ||
console.log(this.obj) | ||
console.log('render') | ||
return <input type="text" v-model={this.double} /> | ||
} | ||
} | ||
|
||
@Component() | ||
class Home1 extends Home { | ||
constructor(private cs: CountService) { | ||
super() | ||
console.log(cs) | ||
} | ||
@Mut() count1 = 111 | ||
render() { | ||
return ( | ||
<div style={{ textAlign: 'center' }}> | ||
<Child> | ||
<div>11111</div> | ||
</Child> | ||
<h2>count: {this.countService.count}</h2> | ||
<button onClick={() => this.countService.add()}>+</button> | ||
<button onClick={() => this.countService.remove()}>-</button> | ||
<p> | ||
矩形大小: 宽度: {this.sizeService.x} 长度: {this.sizeService.y} | ||
</p> | ||
<div | ||
ref={this.sizeService.target} | ||
style={{ | ||
width: '100px', | ||
height: '100px', | ||
resize: 'both', | ||
border: '1px solid #ccc', | ||
overflow: 'scroll', | ||
}} | ||
></div> | ||
<div> | ||
<h5 onClick={() => this.cs.count++}>{this.cs.count}</h5> | ||
<h2 onClick={() => this.count1++}>1111{this.count1}</h2> | ||
{super.render()} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
const app = createApp(Home) | ||
const app = createApp(Home1) | ||
app.mount('#app') |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.