Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div>
  3.     <v-container>
  4.       <v-layout row>
  5.         <v-flex xs12
  6.                 md6
  7.                 offset-md3
  8.                 lg4
  9.                 offset-lg4>
  10.           {{vErrors}}
  11.           <v-text-field name="username"
  12.                         label="Username"
  13.                         v-model="username"
  14.                         id="username"
  15.                         v-validate="'required|email'"
  16.                         :error-messages="vErrors.errorsFor('username')">
  17.           </v-text-field>
  18.  
  19.           <v-text-field name="password"
  20.                         label="Password"
  21.                         v-model="password"
  22.                         id="password"
  23.                         :append-icon="hidden ? 'visibility' : 'visibility_off'"
  24.                         :append-icon-cb="() => (hidden = !hidden)"
  25.                         :type="hidden ? 'password' : 'text'"
  26.                         v-validate="'required|min:8'"
  27.                         :error-messages="vErrors.errorsFor('password')">
  28.           </v-text-field>
  29.           <v-btn light
  30.                  default
  31.                  block
  32.                  class="primary">Sign In
  33.           </v-btn>
  34.         </v-flex>
  35.       </v-layout>
  36.  
  37.     </v-container>
  38.   </div>
  39. </template>
  40.  
  41. <script>
  42.   import Vue from 'vue'
  43.   import VeeValidate from 'vee-validate'
  44.   const config = {
  45.     errorBagName: 'vvErrors'
  46.   }
  47.   Vue.use(VeeValidate, config)
  48.   export default {
  49.     computed: {
  50.       vRules() {
  51.         const rules = {
  52.           fields: this.fields,
  53.           validateOnFor(field) {
  54.             const f = this.fields[field]
  55.             return f && f.validated ? 'blur|keyup' : 'blur'
  56.           }
  57.         }
  58.         return rules
  59.       },
  60.       vErrors() {
  61.         this.vvErrors.errorsFor = function (field) {// eslint-disable-line
  62.           // vuetify expects field with not errors messages to have empty array
  63.           return this.collect(field).length ? this.collect(field) : []
  64.         }
  65.         return this.vvErrors
  66.       }
  67.     },
  68.     data() {
  69.       return {
  70.         hidden: true,
  71.         password: '',
  72.         username: ''
  73.       }
  74.     }
  75.   }
  76. </script>
  77.  
  78. <style scoped>
  79. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement