關於iView中表單的基本使用


 1 <template>
 2     <Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
 3         <Form-item prop="user">
 4             <Input type="text" v-model="formInline.user" placeholder="Username">
 5                 <Icon type="ios-person-outline" slot="prepend"></Icon>
 6             </Input>
 7         </Form-item>
 8         <Form-item prop="password">
 9             <Input type="password" v-model="formInline.password" placeholder="Password">
10                 <Icon type="ios-locked-outline" slot="prepend"></Icon>
11             </Input>
12         </Form-item>
13         <Form-item>
14             <Button type="primary" @click="handleSubmit('formInline')">登錄</Button>
15         </Form-item>
16     </Form>
17 </template>
18 <script>
19     export default {
20         data () {
21             return {
22                 formInline: {
23                     user: '',
24                     password: ''
25                 },
26                 ruleInline: {
27                     user: [
28                         { required: true, message: '請填寫用戶名', trigger: 'blur' }
29                     ],
30                     password: [
31                         { required: true, message: '請填寫密碼', trigger: 'blur' },
32                         { type: 'string', min: 6, message: '密碼長度不能小於6位', trigger: 'blur' }
33                     ]
34                 }
35             }
36         },
37         methods: {
38             handleSubmit(name) {
39                 this.$refs[name].validate((valid) => {
40                     if (valid) {
41                         this.$Message.success('提交成功!');
42                     } else {
43                         this.$Message.error('表單驗證失敗!');
44                     }
45                 })
46             }
47         }
48     }
49 </script>

使用:prop傳遞數據格式為數字、布爾值或函數時,必須帶:

在<Form>標簽中的ref屬性是vue中的ref屬性,被用來給元素或子組件引用信息,引用信息將會被注冊在父組件的 $refs 對象上,主要是用來方便定位到該組件;:model屬性綁定的是一個對象,該對象保存着后面表單項所需要的數據。同時,<Form-item>中的prop屬性綁定的是表單項的數據,將其與表單項關聯起來,在表單驗證中很重要

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM