zoukankan      html  css  js  c++  java
  • Vue中this.$refs[name].resetFields();的使用

    在应用Vue进行项目开发过程中,应用this.$refs[name].resetFields();实现表单搜索元素重置时发现失效。经检查发现是form-item绑定的属性prop与包裹元素el-input绑定值不一致造成的。现梳理有关应用this.$refs[name].resetFields();重置表单方法的注意事项。

    • Form必须要有ref属性
    • Form必须绑定:model
    <Form ref="submitUser" :model="submitUser">
    </FormItem>
    • FormFormItem中必须要有prop属性
    <FormItem prop="realName">
    </FormItem>
    • Form包裹的元素绑定值需与FormItemprop属性名称保持一致(可类比Form表单校验规则)
    <Form ref="submitUser" :model="submitUser">
        <FormItem prop="uname">
            <Input type="text" v-model="submitUser.uname" placeholder="用户名"></Input>
        </FormItem>
        <FormItem prop="passwd">
            <Input type="text" v-model="submitUser.passwd" placeholder="密码"></Input>
        </FormItem>
        <FormItem>
            <Button type="info" @click="query">Login</Button>
            <Button @click="handleReset('submitUser')" style="margin-left: 8px;" type="info">Reset</Button>
        </FormItem>
    </Form>
    <script>
        export default {
            data () {
                return {
                    submitUser:{
                        realName:'',
                        identityNumber:'',
                        mobileNumber:'',
                        telePhoneNumber:''
                    }
                }
            },
            methods:{
                handleReset (name) {
                    this.$refs[name].resetFields();
                }
            }
        }
    </script>

      

  • 相关阅读:
    Get code into Bitbucket fast using Atlassian's SourceTree or the command line
    Django+angularJs
    修改默认python版本
    重拾python mac1.9.2
    REST
    Parameters.Add Parameters.Addrange
    sql建表前删除存在的同名表
    C#1.0
    [转]C#究竟能给开发者带来什么
    Laravel中上传图片至七牛云
  • 原文地址:https://www.cnblogs.com/lyh233/p/14616567.html
Copyright © 2011-2022 走看看