Skip to content

quickstart

quirkyvar edited this page May 19, 2018 · 4 revisions

快速开始

安装

$ npm install --save noform

初体验

import Form, { FormItem, FormCore } from 'noform'; // 引入

const Input = ({ value = '', status }) => { // 模拟input
    if (status === 'edit') {
        return <input value={value} />
    } else {
        return `presenting preview val: ${value}`
    }
};

class App extends React.Component {
    componentWillMount () => { // 初始化表单核心
        window.core = this.core = new FormCore();
    }

    render() { // 注入核心        
        return <Form core={this.core}>
            <FormItem name="username" label="username"><Input /></FormItem>
        </Form>
    }
}

现在到控制台中使用core感受一下

core.setValue('username', 'john');
core.setStatus('username', 'preview');
<script> console.log('123'); </script>
Clone this wiki locally