Skip to content

Commit fd58303

Browse files
committed
docs: readme
1 parent 9953bd5 commit fd58303

File tree

3 files changed

+71
-59
lines changed

3 files changed

+71
-59
lines changed

README.CN.md

+27-23
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,22 @@ export default defineConfig({
329329

330330
![](./assets/omi-vue.gif)
331331

332-
my-counter.ts:
332+
my-counter.tsx:
333333

334334
```tsx
335-
import { define, Component, h } from 'omi'
336-
337-
define('my-counter', class extends Component {
338-
339-
static propTypes = {
340-
count: Number
341-
}
342-
343-
static observedAttributes = ['count']
344-
345-
attributeChangedCallback(name, oldValue, newValue) {
346-
this.state[name] = newValue
347-
this.update()
335+
import { tag, Component, h, bind } from 'omi'
336+
337+
@tag('my-counter')
338+
class MyCounter extends Component {
339+
static props = {
340+
count: {
341+
type: Number,
342+
default: 0,
343+
changed(newValue, oldValue) {
344+
this.state.count = newValue
345+
this.update()
346+
}
347+
}
348348
}
349349

350350
state = {
@@ -355,26 +355,30 @@ define('my-counter', class extends Component {
355355
this.state.count = this.props.count
356356
}
357357

358-
sub = () => {
358+
@bind
359+
sub() {
359360
this.state.count--
360361
this.update()
361362
this.fire('change', this.state.count)
362363
}
363364

364-
add = () => {
365+
@bind
366+
add() {
365367
this.state.count++
366368
this.update()
367369
this.fire('change', this.state.count)
368370
}
369371

370-
render(props) {
371-
return [
372-
h('button', { onClick: this.sub }, '-'),
373-
h('span', null, this.state.count),
374-
h('button', { onClick: this.add }, '+')
375-
]
372+
render() {
373+
return (
374+
<>
375+
<button onClick={this.sub}>-</button>
376+
<span>{this.state.count}</span>
377+
<button onClick={this.add}>+</button>
378+
</>
379+
)
376380
}
377-
})
381+
}
378382
```
379383

380384
Using in Vue3:

README.md

+27-23
Original file line numberDiff line numberDiff line change
@@ -348,22 +348,22 @@ The case of using Omi component in Vue is as follows:
348348

349349
![](./assets/omi-vue.gif)
350350

351-
my-counter.ts:
351+
my-counter.tsx:
352352

353353
```tsx
354-
import { define, Component, h } from 'omi'
355-
356-
define('my-counter', class extends Component {
357-
358-
static propTypes = {
359-
count: Number
360-
}
361-
362-
static observedAttributes = ['count']
363-
364-
attributeChangedCallback(name, oldValue, newValue) {
365-
this.state[name] = newValue
366-
this.update()
354+
import { tag, Component, h, bind } from 'omi'
355+
356+
@tag('my-counter')
357+
class MyCounter extends Component {
358+
static props = {
359+
count: {
360+
type: Number,
361+
default: 0,
362+
changed(newValue, oldValue) {
363+
this.state.count = newValue
364+
this.update()
365+
}
366+
}
367367
}
368368

369369
state = {
@@ -374,26 +374,30 @@ define('my-counter', class extends Component {
374374
this.state.count = this.props.count
375375
}
376376

377-
sub = () => {
377+
@bind
378+
sub() {
378379
this.state.count--
379380
this.update()
380381
this.fire('change', this.state.count)
381382
}
382383

383-
add = () => {
384+
@bind
385+
add() {
384386
this.state.count++
385387
this.update()
386388
this.fire('change', this.state.count)
387389
}
388390

389-
render(props) {
390-
return [
391-
h('button', { onClick: this.sub }, '-'),
392-
h('span', null, this.state.count),
393-
h('button', { onClick: this.add }, '+')
394-
]
391+
render() {
392+
return (
393+
<>
394+
<button onClick={this.sub}>-</button>
395+
<span>{this.state.count}</span>
396+
<button onClick={this.add}>+</button>
397+
</>
398+
)
395399
}
396-
})
400+
}
397401
```
398402

399403
Using in Vue3:

packages/omi/README.md

+17-13
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,13 @@ The case of using Omi component in Vue is as follows:
346346

347347
![](./assets/omi-vue.gif)
348348

349-
my-counter.ts:
349+
my-counter.tsx:
350350

351351
```tsx
352-
import { define, Component, h } from 'omi'
353-
354-
define('my-counter', class extends Component {
352+
import { tag, Component, h, bind } from 'omi'
355353

354+
@tag('my-counter')
355+
class MyCounter extends Component {
356356
static props = {
357357
count: {
358358
type: Number,
@@ -372,26 +372,30 @@ define('my-counter', class extends Component {
372372
this.state.count = this.props.count
373373
}
374374

375-
sub = () => {
375+
@bind
376+
sub() {
376377
this.state.count--
377378
this.update()
378379
this.fire('change', this.state.count)
379380
}
380381

381-
add = () => {
382+
@bind
383+
add() {
382384
this.state.count++
383385
this.update()
384386
this.fire('change', this.state.count)
385387
}
386388

387-
render(props) {
388-
return [
389-
h('button', { onClick: this.sub }, '-'),
390-
h('span', null, this.state.count),
391-
h('button', { onClick: this.add }, '+')
392-
]
389+
render() {
390+
return (
391+
<>
392+
<button onClick={this.sub}>-</button>
393+
<span>{this.state.count}</span>
394+
<button onClick={this.add}>+</button>
395+
</>
396+
)
393397
}
394-
})
398+
}
395399
```
396400

397401
Using in Vue3:

0 commit comments

Comments
 (0)