zoukankan      html  css  js  c++  java
  • vue+vue-validator 表单验证

    1.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <div id="app">
            <validator name="myForm">
                <form novalidate>
                    Zip: <input type="text" v-validate:zip="['required']"><br />
                    <div>
                        <span v-if="$myForm.zip.required">Zip code is required.</span>
                    </div>
                </form>
            </validator>
        </div>
        <script src="https://unpkg.com/vue@1.0.26/dist/vue.min.js"></script>
        <script src="https://cdn.bootcss.com/vue-validator/2.1.3/vue-validator.js"></script>
        <script>
            new Vue({
                el:"#app"
            })
        </script>
    </body>
    </html>

    2.

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title>radio button validation example</title>
        <script src="../../node_modules/vue/dist/vue.js"></script>
        <script src="../../dist/vue-validator.js"></script>
        <style>
          input.invalid { border-color: red; }
          .errors { color: red; }
        </style>
      </head>
      <body>
        <div id="app">
          <h1>Survey</h1>
          <validity-group field="fruits" v-model="validation" :validators="{
            required: { message: requiredErrorMsg }
          }">
            <legend>Which do you like fruit ?</legend>
            <input id="apple" type="radio" name="fruit" value="apple" @change="handleValidate" @focusin="handleValidate">
            <label for="apple">Apple</label>
            <input id="orange" type="radio" name="fruit" value="orange" @change="handleValidate" @focusin="handleValidate">
            <label for="orange">Orage</label>
            <input id="grape" type="radio" name="fruit" value="grage" @change="handleValidate" @focusin="handleValidate">
            <label for="grape">Grape</label>
            <input id="banana" type="radio" name="fruit" value="banana" @change="handleValidate" @focusin="handleValidate">
            <label for="banana">Banana</label>
            <ul class="errors">
              <li v-for="error in validation.result.errors">
                <p :class="error.field + '-' + error.validator">{{error.message}}</p>
              </li>
            </ul>
          </validity-group>
        </div>
        <script>
          new Vue({
            data: {
              validation: {
                result: {}
              }
            },
            computed: {
              requiredErrorMsg: function () {
                return 'Required fruit !!'
              }
            },
            methods: {
              handleValidate: function (e) {
                var $validity = e.target.$validity 
                $validity.validate()
              }
            }
          }).$mount('#app')
        </script>
      </body>
    </html>
    

  • 相关阅读:
    0x00000090 该内存不能read written
    AutoCAD系统变量:EDGEMODE
    AutoCAD.net: DoubleClick
    Access 类型转换函数
    无法更改文件夹的隐藏属性 解决方法!
    Windows防火墙无法启动解决办法
    AutoCAD.net: DrawOrderChange display order of the entities in the drawing
    C#调用C++编写的COM DLL
    编辑AutoCAD 2010中新出现的CUIx文件[转]
    hook钩子
  • 原文地址:https://www.cnblogs.com/xutongbao/p/9924950.html
Copyright © 2011-2022 走看看