import { storiesOf } from '@storybook/vue' import { defineComponent, ref } from '@vue/composition-api' import { useForm } from '../index' import md from '../docs/form.md' const Count = defineComponent({ template: `
EXAMPLE - national form
用户名: {{fields.userName}}
电子邮箱: {{fields.email}}
类型: {{fields.type}}

用户名:  
电子邮箱:
类型:   
count: {{count}}

`, setup() { const { fields, rules, reset, valid, commit } = useForm() fields.value = { userName: "", email: "", type: "A" } const count = ref(0) commit.value = function(){ count.value += 1 } // 在vue2.0 optionCompoment语法中使用fields时需要将fields本身也转为ref对象 // return { // fields: ref(fields), // reset, commit, count // } return { fields, reset, commit, count } } }) storiesOf('UI|useForm', module) .add('form', () => Count, { readme: { sidebar: md } })