update readme
This commit is contained in:
parent
89fafd95cb
commit
6138bb1ec4
|
@ -1,76 +1,59 @@
|
|||
# omi-page
|
||||
|
||||
Tiny client-side router by [page](https://github.com/visionmedia/page.js).
|
||||
Support touch and gesture events in your Omi project.
|
||||
|
||||
[→ demo](https://tencent.github.io/omi/packages/omi-page/examples/simple/)
|
||||
[→ demo](https://tencent.github.io/omi/packages/omi-finger/examples/simple/)
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { render, tag, WeElement } from 'omi'
|
||||
import page from 'omi-page'
|
||||
import 'omi-finger'
|
||||
|
||||
@tag('my-app')
|
||||
class MyApp extends WeElement {
|
||||
installed() {
|
||||
page('/', this.index)
|
||||
page('/about', this.about)
|
||||
page('/contact', this.contact)
|
||||
page('/contact/:contactName', this.contact)
|
||||
page('*', this.notfound)
|
||||
page()
|
||||
}
|
||||
install() {
|
||||
this.data.wording = 'Tap or Swipe Me!'
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<ul>
|
||||
<li><a href="/">/</a></li>
|
||||
<li><a href="/about">/about</a></li>
|
||||
<li><a href="/contact">/contact</a></li>
|
||||
<li><a href="/contact/me">/contact/me</a></li>
|
||||
<li><a href="/contact/me?a=b">/contact/me?a=b</a></li>
|
||||
<li><a href="/not-found?foo=bar">/not-found</a></li>
|
||||
</ul>
|
||||
<p>
|
||||
{this.data.path}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
handleTap = (evt) => {
|
||||
this.data.wording += '\r\nTap'
|
||||
this.update()
|
||||
}
|
||||
|
||||
index = (ctx) => {
|
||||
this.data.path = ctx.path
|
||||
this.update()
|
||||
}
|
||||
handleSwipe = (evt) => {
|
||||
this.data.wording += '\r\nSwipe-' + evt.direction
|
||||
this.update()
|
||||
}
|
||||
|
||||
about = (ctx) => {
|
||||
this.data.path = ctx.path
|
||||
this.update()
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<omi-finger onTap={this.handleTap} abc={{a:1}} onSwipe={this.handleSwipe}>
|
||||
<div class="touchArea" >
|
||||
{this.data.wording}
|
||||
</div>
|
||||
</omi-finger>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
contact = (ctx) => {
|
||||
this.data.path = ctx.path
|
||||
this.update()
|
||||
}
|
||||
|
||||
notfound = (ctx) => {
|
||||
this.data.path = ctx.path
|
||||
this.update()
|
||||
}
|
||||
css() {
|
||||
return `.touchArea{
|
||||
background-color: green;
|
||||
width: 200px;
|
||||
min-height: 200px;
|
||||
text-align: center;
|
||||
color:white;
|
||||
height:auto;
|
||||
white-space: pre-line;
|
||||
}`
|
||||
}
|
||||
}
|
||||
|
||||
render(<my-app></my-app>, 'body')
|
||||
```
|
||||
|
||||
## page.base([path])
|
||||
|
||||
Get or set the base path. For example if page.js is operating within /blog/* set the base path to "/blog":
|
||||
|
||||
```js
|
||||
page.base('/blog')
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT © dntzhang
|
||||
|
|
Loading…
Reference in New Issue