1. 程式人生 > >直接引用vee-validate校驗插件

直接引用vee-validate校驗插件

hellip var date div 下載 guide code pla asc

直接在頁面引用vee-validate

源文件下載地址:http://www.bootcdn.cn/vee-validate/

官方api https://baianat.github.io/vee-validate/guide/rules.html#is-not

 <script th:src="@{/js/vee-validate/vee-validate.min.js}"></script>
 <script th:src="@{/js/vee-validate/vee-zh_CN.js}"></script>
 <input v-validate="‘required|phone‘" :class="{‘input‘: true, ‘is-danger‘: errors.has(‘phone‘) }" name="phone" type="text" placeholder="phone" />
    <br/>
    <span v-show="errors.has(‘phone‘)" style="color: red;font-size: 12px;">{{ errors.first(‘phone‘) }}</span>
    <br/>
    <input v-validate="‘required|email‘" :class="{‘input‘: true, ‘is-danger‘: errors.has(‘email‘) }" name="email" type="text" placeholder="email" />
    <br/>
    <span v-show="errors.has(‘email‘)" style="color: red;font-size: 12px;">{{ errors.first(‘email‘) }}</span>
<script th:inline="javascript">
/*<![CDATA[*/
//引入vue後,需要添加vee-validata的js和語言包文件(目前只用中文)
 VeeValidate.Validator.localize(‘zh_CN‘);
//js使用方式,指定語言、修改默認提示,添加自定義驗證 VeeValidate.Validator.localize({ zh_CN:{message:{ required:
function (name) { return name+"不能為空!"; }, email:
function () { return "郵箱格式無效" } }} }); VeeValidate.Validator.extend(‘phone‘,{ getMessage:function () { return "請輸入正確手機號!"; }, validate:function (value) { return /^1\d{10}$/.test(value); } }); Vue.use(VeeValidate);
var vue = new Vue({
el: "#test",
data: {
submitDisabled: true,
ruleForm: {
…………代碼省

直接引用vee-validate校驗插件