From 22ac4b5bf098e9dac6dde091514af5dca9052310 Mon Sep 17 00:00:00 2001 From: dntzhang Date: Thu, 18 Oct 2018 08:22:41 +0800 Subject: [PATCH] update docs --- assets/first-element.jpg | Bin 0 -> 10680 bytes docs/docs.md | 0 docs/main-concepts.cn.md | 128 +++++++++++++++++++++++++++++++++++ docs/main-concepts.md | 142 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 270 insertions(+) create mode 100644 assets/first-element.jpg delete mode 100644 docs/docs.md create mode 100644 docs/main-concepts.cn.md create mode 100644 docs/main-concepts.md diff --git a/assets/first-element.jpg b/assets/first-element.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e1fffa09c5177730a2d957ab705843332b2899a9 GIT binary patch literal 10680 zcmbVw2V7Ijx9*07-lYjBM5>B35mD(NO{6yg0V$yvLX_T7kRnx3;Q#_k5s@ZHGn6PG zML?uWsG*9q1O%c4@-}*o=bZn$@80*`ggtzFtu<@bw`T2`{oCZv8|V7Z@OjZyaLRUl`N@9FD(m>`xmr6EIgaPe9D<xj=b~r=x-4pJP8ed24{V1O!3(fg4=+Fu(i&0D-yt=$e5T^aD}$LYW-e zgE2r{oZ*)>L3{?paR`*&VGN*8NUgV@>7o2Ep3gyU8i#Qn%6o1)TrmPMSk;hOxQF(k zJvbMHbj!!+&lsTmo*o8=^MZ3hFT=fm@&)}s`F-5XbU-;cFVw@w%k0mw&<8H=TDpJQ zSGjrV9Lf*JVsCl;tWhvFDoQV3lSA&{TvU<{UYgn<27OW)!9C3n^LdE<01FBS01lu4 zN3eGSJb`@x2ABZafI9g97T^VHTmW~#1C+o)EgY161Y+<;Y3>h{|w4A21Yd_kG(|H03%SeF0vgMxBH zrJ=Imr2xGORf1lCUIbuJ6{spy8G0F%UW6+A_H6`?`HRtEJj>uLzx><=XN3Q>vjDlj z13CHt4q%T1El_~>Zx8><$^%~ClYeU>yzJeb`jYYg$dx-d67kzY;$Imx{GW18HBa@0 zY8dRts3v~R)#MxfXv}sew#AevU+fS#Sq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*4~S0n5=MeF@@$c1i3F7;Bu`4oCB4m95_J6W6AW;zv?&O!R}T znT+~WiK&khd9dp8GEQlZhQbfOTw-Jv4|+3M@$9YUyapLi9NpvyWF-TAa-=9dO_<>3 q2{Mp__)f1F8@`lzpkA1F=l@QmLLU5ezW(Do`#-Hello, world! + ) + } +} + +render(, 'body') +``` + +在 HTML 开发者工具里看看渲染得到的结构: + +![fe](../assets/first-element.jpg) + +除了渲染到 body,你可以在其他任意自定义元素中使用 `my-first-element`。 + + +### Props + +```js +import { WeElement, tag, render } from 'omi' + +@tag('my-first-element') +class MyFirstElement extends WeElement { + render(props) { + return ( +

Hello, {props.name}!

+ ) + } +} + +render(, 'body') +``` + +你也可以传任意类型的数据给 props: + +```js +import { WeElement, tag, render } from 'omi' + +@tag('my-first-element') +class MyFirstElement extends WeElement { + render(props) { + return ( +

Hello, {props.myObj.name}!

+ ) + } +} + +render(, 'body') +``` + +`my-obj` 将映射到 myObj,驼峰的方式。 + + +### Event + +```js +class MyFirstElement extends WeElement { + onClick = (evt) => { + alert('Hello Omi!') + } + + render() { + return ( +

Hello, wrold!

+ ) + } +} +``` + +### Custom Event + +```js +@tag('my-first-element') +class MyFirstElement extends WeElement { + onClick = (evt) => { + this.fire('myevent', { name: 'abc' }) + } + + render(props) { + return ( +

Hello, world!

+ ) + } +} + +render( { alert(evt.detail.name) }}>, 'body') +``` + +Tirgger custom event by `this.fire` and get the data by `evt.detail`. + +### Ref + +```js +@tag('my-first-element') +class MyFirstElement extends WeElement { + onClick = (evt) => { + console.log(this.h1) + } + + render(props) { + return ( +
+

{ this.h1 = e }} onClick={this.onClick}>Hello, world!

+
+ ) + } +} + +render(, 'body') +``` + +Get the element by `ref={e => { this.anyNameYouWant = e }}` \ No newline at end of file diff --git a/docs/main-concepts.md b/docs/main-concepts.md new file mode 100644 index 000000000..5f6b85502 --- /dev/null +++ b/docs/main-concepts.md @@ -0,0 +1,142 @@ +## Omi Docs + +- [My First Element](#my-first-element) +- [Props](#props) +- [Event](#event) +- [Custom Event](#custom-event) +- [Ref](#ref) + +### My First Element + +```js +import { WeElement, tag, render } from 'omi' + +@tag('my-first-element') +class MyFirstElement extends WeElement { + render() { + return ( +

Hello, world!

+ ) + } +} + +render(, 'body') +``` + +Look at the rendering structure in the HTML developer tool: + +![fe](../assets/first-element.jpg) + +You can also use `my-first-element` in any other custom element. Such as: + +```js +import { WeElement, tag, render } from 'omi' +import './my-first-element' + +@tag('other-element') +class OtherElement extends WeElement { + render() { + return ( +
+ +
+ ) + } +} +``` + +### Props + +```js +import { WeElement, tag, render } from 'omi' + +@tag('my-first-element') +class MyFirstElement extends WeElement { + render(props) { + return ( +

Hello, {props.name}!

+ ) + } +} + +render(, 'body') +``` + +You can also transmit any type of data to props: + +```js +import { WeElement, tag, render } from 'omi' + +@tag('my-first-element') +class MyFirstElement extends WeElement { + render(props) { + return ( +

Hello, {props.myObj.name}!

+ ) + } +} + +render(, 'body') +``` + +The `my-obj` will map to myObj with camel-case. + +### Event + +```js +class MyFirstElement extends WeElement { + onClick = (evt) => { + alert('Hello Omi!') + } + + render() { + return ( +

Hello, wrold!

+ ) + } +} +``` + +### Custom Event + +```js +@tag('my-first-element') +class MyFirstElement extends WeElement { + onClick = (evt) => { + this.fire('myevent', { name: 'abc' }) + } + + render(props) { + return ( +

Hello, world!

+ ) + } +} + +render( { alert(evt.detail.name) }}>, 'body') +``` + +Tirgger custom event by `this.fire` and get the data by `evt.detail`. + +### Ref + +```js +@tag('my-first-element') +class MyFirstElement extends WeElement { + onClick = (evt) => { + console.log(this.h1) + } + + render(props) { + return ( +
+

{ this.h1 = e }} onClick={this.onClick}>Hello, world!

+
+ ) + } +} + +render(, 'body') +``` + +Get the element by `ref={e => { this.anyNameYouWant = e }}` \ No newline at end of file