3-8 form组件

form

基础库 1.0.0 开始支持,低版本需做兼容处理

表单。将组件内的用户输入的<switch> <input> <checkbox> <slider> <radio> <picker> 提交。

当点击 <form> 表单中 form-type 为 submit 的 <button> 组件时,会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key。

属性类型默认值必填说明最低版本
report-submitbooleanfalse是否返回 formId 用于发送模板消息1.0.0
report-submit-timeoutnumber0等待一段时间(毫秒数)以确认 formId 是否生效。如果未指定这个参数,formId 有很小的概率是无效的(如遇到网络失败的情况)。指定这个参数将可以检测 formId 是否有效,以这个参数的时间作为这项检测的超时时间。如果失败,将返回 requestFormId:fail 开头的 formId2.6.2
bindsubmiteventhandle 携带 form 中的数据触发 submit 事件,event.detail = {value : {'name': 'value'} , formId: ''}1.0.0
bindreseteventhandle 表单重置时会触发 reset 事件1.0.0

示例代码

// 在开发者工具中预览效果

<form bindsubmit="formSubmit" bindreset="formReset">
  <view class="section section_gap">
    <view class="section__title">switch</view>
    <switch name="switch" />
  </view>
  <view class="section section_gap">
    <view class="section__title">slider</view>
    <slider name="slider" show-value></slider>
  </view>

  <view class="section">
    <view class="section__title">input</view>
    <input name="input" placeholder="please input here" />
  </view>
  <view class="section section_gap">
    <view class="section__title">radio</view>
    <radio-group name="radio-group">
      <label>
        <radio value="radio1" />
        radio1
      </label>
      <label>
        <radio value="radio2" />
        radio2
      </label>
    </radio-group>
  </view>
  <view class="section section_gap">
    <view class="section__title">checkbox</view>
    <checkbox-group name="checkbox">
      <label>
        <checkbox value="checkbox1" />
        checkbox1
      </label>
      <label>
        <checkbox value="checkbox2" />
        checkbox2
      </label>
    </checkbox-group>
  </view>
  <view class="btn-area">
    <button form-type="submit">Submit</button>
    <button form-type="reset">Reset</button>
  </view>
</form>
Page({
  formSubmit(e) {
    console.log('form发生了submit事件,携带数据为:', e.detail.value)
  },
  formReset() {
    console.log('form发生了reset事件')
  }
})

输出log(以字典的形式输出数据,其中name属性作为key值,value属性作为value)

以上内容来自文档: https://developers.weixin.qq.com/miniprogram/dev/component/form.html

关于与button关联可以查看:https://blog.csdn.net/u012717715/article/details/90210417

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3 Form-Create-Designer是一个基于Vue3的表单设计器,支持自定义组件。如果你想要添加自定义组件,可以按照以下步骤进行操作: 1. 创建自定义组件 首先需要创建一个Vue3组件,可以通过Vue CLI等工具进行创建。在组件内部实现自己的功能和样式,并在最后通过export default导出该组件。 例如,我们创建了一个名为MyInput的组件: ```vue <template> <div> <input v-model="value" :placeholder="placeholder" /> </div> </template> <script> import { defineComponent } from 'vue' export default defineComponent({ props: { value: { type: String, default: '' }, placeholder: { type: String, default: '请输入' } } }) </script> <style scoped> div { border: 1px solid #ccc; padding: 10px; } input { width: 100%; height: 32px; border: none; border-bottom: 1px solid #ccc; } </style> ``` 2. 注册自定义组件 在使用Form-Create-Designer的页面中,需要通过Vue3的全局组件注册方式来注册自定义组件。在代码中引入MyInput组件,并使用Vue3的component方法进行注册。 例如: ```vue <template> <div> <form-create-designer v-model="form" :schema="schema" /> </div> </template> <script> import { defineComponent } from 'vue' import FormCreateDesigner from 'vue3-form-create-designer' import MyInput from './MyInput.vue' export default defineComponent({ components: { FormCreateDesigner, MyInput }, data() { return { form: {}, schema: { fields: [ { type: 'MyInput', model: 'input', label: '自定义输入框' } ] } } } }) </script> ``` 在上面的代码中,我们将MyInput组件注册为全局组件,并在schema中使用了type为MyInput的自定义组件。 3. 使用自定义组件 在注册好自定义组件后,就可以在Schema中使用该自定义组件了。可以在Schema中使用type属性指定该字段的类型为我们刚刚注册的自定义组件。 例如: ```js { type: 'MyInput', model: 'input', label: '自定义输入框' } ``` 这样就可以在Form-Create-Designer中使用自定义组件了。 希望这个回答对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值