• ant-design-vue 之form表单使用


    ant-design-vue 之form表单使用

    主要代码: v-decorator, setFieldsValue, getFieldsValue, resetFields, validateFields

                    this.form.setFieldsValue({"username":['username_ddddd'],"nickname":['nickname_ddddd']}); //设置值
    
                    this.form.getFieldsValue();// 获取所有值
                    this.form.getFieldsValue(['username','nickname']); // 获取某一个值
                    
                    this.form.resetFields();  // 重置表单值
                    
                    this.form.validateFields(err => {  // 校验所有的值
                        if (!err) {
                            console.info('success');
                        }else {
                            console.log(err);
                        }
                    });
                    
                    this.form.validateFields(['nickname'],(err)=>{ // 校验某个值
                        if (!err) {
                            console.log('success');
                        }else {
                            console.log(err);
                        }
                    });

    demo 练习

    <template>
        <div>
            <a-form :form="form">
                
                <a-form-item label="Name">
                    <a-input placeholder="Please input your name"
                            v-decorator="username" />
                </a-form-item>
                
                <a-form-item  label="Nickname">
                    <a-input  placeholder="Please input your nickname" 
                              v-decorator="['nickname',{ rules: [{ required: true, message: 'Please input your nickname' }] },]"/>
                </a-form-item>
                
                <button @click="fei_form">form功能测试</button>
            </a-form>
        </div>
    </template>
    <script>
        
        /* 这是ant-design-vue */
        import Vue from 'vue'
        import Antd, { message,Select } from 'ant-design-vue'  //这是ant-design-vue
        import 'ant-design-vue/dist/antd.css'
        Vue.use(Antd);
        /* 这是ant-design-vue */
    
    
        export default {
            data() {
                return {
                    form: this.$form.createForm(this, { name: 'form_rule' }), // 定义form
                    username: ['username', {rules: [{required: true, message: 'Please input your username'}]}]
                }
            },
            methods: {
    
                fei_form() {
                    
                    this.form.setFieldsValue({"username":['username_ddddd'],"nickname":['nickname_ddddd']}); //设置值
                    
                    this.form.getFieldsValue();// 获取所有值
                    this.form.getFieldsValue(['username','nickname']); // 获取某一个值
                    
                    this.form.resetFields();  // 重置表单值
                    
                    this.form.validateFields(err => {  // 校验所有的值
                        if (!err) {
                            console.info('success');
                        }else {
                            console.log(err);
                        }
                    });
                    
                    this.form.validateFields(['nickname'],(err)=>{ // 校验某个值
                        if (!err) {
                            console.log('success');
                        }else {
                            console.log(err);
                        }
                    });
                    
                }
            },
            watch: {
    
            },
        };
    </script>
    
    <style scoped>
    
    </style>
    View Code

    Form 表单

  • 相关阅读:
    设计模式之_6大设计原则(转)
    Django-ORM多表操作(进阶)
    03-django模型(1)
    02-Django基础知识
    web开篇
    body标签中的相关标签
    01-前端初识
    Flask简述
    浅析设计模式
    Python的单例模式
  • 原文地址:https://www.cnblogs.com/dafei4/p/13424918.html
Copyright © 2020-2023  润新知