github Tencent/omi v6.10.1

latest releases: v7.6.6, v7.6.1, v7.5.6...
4 years ago

Add the fourth parameter to define method, can configure CSS and lifecycle functions.

import { render, define } from 'omi'

class Store {
  data = {
    count: 1
  }
  sub = () => {
    this.data.count--
  }
  add = () => {
    this.data.count++
  }
}

define('my-counter', ['count'], _ => (
  <div>
    <button onClick={_.store.sub}>-</button>
    <span>{_.store.data.count}</span>
    <button onClick={_.store.add}>+</button>
  </div>
), {
    css: `span { color: red; }`,
    installed() {
      console.log('installed')
    }
  })

render(<my-counter />, 'body', new Store)

Don't miss a new omi release

NewReleases is sending notifications on new releases.