Giter Club home page Giter Club logo

Comments (6)

ch656409110 avatar ch656409110 commented on May 18, 2024

我感觉我描述的不清楚,那个标签被过滤了,我贴下组件代码:

`

<a-form @submit="handleSubmit" :autoFormCreate="(form)=>{this.form = form}">


  <a-form-item
    label="出生日期"
    :labelCol="{lg: {span: 2}, sm: {span: 7}}"
    :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
    fieldDecoratorId="birthday"
    :fieldDecoratorOptions="{rules: [{ required: false, message: '请选择出生日期' }]}"
  >
    <a-date-picker name="birthday" style="width: 100%" />
  </a-form-item>
  获取的值无法格式化到yyyy-MM-dd
  <a-form-item
    label="出生时间"
    :labelCol="{lg: {span: 2}, sm: {span: 7}}"
    :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
    fieldDecoratorId="birthtime"
    :fieldDecoratorOptions="{rules: [{ required: false, message: '请选择出生时间' }]}"
  >
    <a-time-picker name="birthday" style="width: 30%"  />
  </a-form-item>



  <a-form-item
    label="性别"
    :labelCol="{lg: {span: 2}, sm: {span: 7}}"
    :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
    fieldDecoratorId="sex"
    :fieldDecoratorOptions="{rules: [{ required: true, message: '请选择出生日期' }]}"
  >
    <a-radio-group v-model="sex">
      <a-radio :value="1">男</a-radio>
      <a-radio :value="2">女</a-radio>
    </a-radio-group>
  </a-form-item>
  绑定的值只能数字,中文汉字无效,纠结了半天,如果绑定了fieldDecoratorId,会导致vue加载单选框默认不选中,但是如果不给fieldDecoratorId,form就取不到值,原因未知。


  <a-form-item
    label="居住城市"
    :labelCol="{lg: {span: 2}, sm: {span: 7}}"
    :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
    fieldDecoratorId="city"
    :fieldDecoratorOptions="{rules: [{ required: true, message: '请选择居住城市' }]}"
    >
    <a-checkbox-group  @change="onCheckboxChange">
        <a-checkbox value="上海">上海</a-checkbox>
        <a-checkbox value="无锡" >无锡</a-checkbox>
        <a-checkbox value="苏州" >苏州</a-checkbox>
        <a-checkbox value="杭州" >杭州</a-checkbox>
    </a-checkbox-group>
  </a-form-item> 
  <a-form-item
    label="工作时间"
    :labelCol="{lg: {span: 2}, sm: {span: 7}}"
    :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
    fieldDecoratorId="workTime"
    :fieldDecoratorOptions="{rules: [{ required: true, message: '请选择工作时间' }]}"
  >
    <a-range-picker name="workTime" style="width: 100%"/>
  </a-form-item>

  <a-form-item
    label="自我描述"
    :labelCol="{lg: {span: 2}, sm: {span: 7}}"
    :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
    fieldDecoratorId="description"
    :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入自我描述' }]}"
  >
    <a-textarea rows="5" placeholder="请输入自我描述"/>
  </a-form-item>


  <a-form-item
    label="兴趣爱好"
    :labelCol="{lg: {span: 2}, sm: {span: 7}}"
    :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
    fieldDecoratorId="like"
    :fieldDecoratorOptions="{rules: [{ required: false, message: '请选择兴趣爱好' }]}"
  >
    <a-select defaultValue="movie">
      <a-select-option value="game">游戏</a-select-option>
      <a-select-option value="movie">电影</a-select-option> 
      <a-select-option value="lvyou">旅游</a-select-option> 
    </a-select>
  </a-form-item>

  <a-form-item
    label="掌握语言"
    :labelCol="{lg: {span: 2}, sm: {span: 7}}"
    :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
    fieldDecoratorId="language"
    :fieldDecoratorOptions="{rules: [{ required: false, message: '请选择掌握语言' }]}"
  >
    <a-select  mode="multiple">
      <a-select-option value="java">java</a-select-option>
      <a-select-option value=".net">.net</a-select-option>
      <a-select-option value="javascript">javascript</a-select-option>
      <a-select-option value="html5">html5</a-select-option>
      <a-select-option value="android">android</a-select-option>
    </a-select>
  </a-form-item>

  默认是单选框模式,需要在select上加上mode="multiple"后变成多选框模式
  必须指定所有option的value的值,否则控件不显示,目前还不够灵活,如果指定默认选中需要在select上加上mode="multiple"
  并且defaultValue="movie" 无效。
  <a-form-item :wrapperCol="{ span: 24 }" style="text-align: center">
    <a-button htmlType="submit" type="primary">提交</a-button>
    <a-button style="margin-left: 8px" v-on:click="tempSave">暂存</a-button>
  </a-form-item>


</a-form>
<div id="result" v-html="result"></div>
<script> import notification from 'ant-design-vue/es/notification' import moment from 'moment'; import 'moment/locale/zh-cn'; moment.locale('zh-cn'); export default { name: "simpleForm", data() { return { sex: 1, result: "" }; }, methods: { handleSubmit(e) { e.preventDefault(); this.form.validateFields((err, values) => { if (!err) { // eslint-disable-next-line no-console console.log("Received values of form: ", values); //this.$data.result = values this.result = values; //两种方式都可以, 这里的this指向vue } }); }, tempSave(){ notification.success({ message: '测试',description: "你点了暂存" }); }, onCheckboxChange(checkedValues){ notification.info({ message: '测试',description: checkedValues.toString() }); } } }; </script> <style scoped> </style>

`

from ant-design-vue-pro.

ch656409110 avatar ch656409110 commented on May 18, 2024

第一个问题找到方法了,需要自己转换下:

if(queryParam.publishTime){ queryParam.publishTime = queryParam.publishTime.format('YYYY-MM-DD'); }

from ant-design-vue-pro.

sendya avatar sendya commented on May 18, 2024

时间自己用 moment 转换

from ant-design-vue-pro.

ch656409110 avatar ch656409110 commented on May 18, 2024

你们好辛苦啊,不容易!

from ant-design-vue-pro.

lettgers avatar lettgers commented on May 18, 2024

时间不能自己转一下吗 既然设置了format获取到的值应该是格式化之后的结果才对啊

from ant-design-vue-pro.

watsonhaw5566 avatar watsonhaw5566 commented on May 18, 2024

@lettgers format的值@change第二个参数dateString里面获取.
image

from ant-design-vue-pro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.