最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue Vee-validate marking valid URLs as invalid - Stack Overflow

programmeradmin2浏览0评论

For my Vuejs app I'm using Vee-validate for validation. Currently it's marking valid URLs, like http://localhost:3000, as invalid.

This is happening on their sample also: .html#rule-url

If you enter http://localhost:3000 in their sample, you'll see the message The field field is not a valid URL.

For my Vuejs app I'm using Vee-validate for validation. Currently it's marking valid URLs, like http://localhost:3000, as invalid.

This is happening on their sample also: http://vee-validate.logaretm./rules.html#rule-url

If you enter http://localhost:3000 in their sample, you'll see the message The field field is not a valid URL.

Share Improve this question edited Oct 25, 2017 at 2:09 Bert 82.5k17 gold badges203 silver badges166 bronze badges asked Oct 20, 2017 at 22:37 Gene ParcellanoGene Parcellano 6,0445 gold badges39 silver badges44 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

After searching, I found some related issues on Vee-validate's Github, but none solved my problem pletely. Here's what I had to do to get it to validate localhost URLs:

  1. Add the validator package

    npm install validator
    
  2. Add a new rule:

    const urlFixRule = (value) => {
        return isURL(value, {
            require_tld: false
        });
    };
    
  3. Apply the new rule:

    VeeValidate.Validator.extend('url', urlFixRule);
    

How it looks in my js file

import Vue from 'vue';
import isURL from 'validator/lib/isURL';
import VeeValidate from 'vee-validate';
import App from './App';

// Form Validation (https://github./baianat/vee-validate)
Vue.use(VeeValidate);

// Temporary Fix for Vee-validate bug, until the next release
const urlFixRule = (value) => {
  return isURL(value, {
    require_tld: false
  });
};
VeeValidate.Validator.extend('url', urlFixRule);

/* eslint-disable no-new */
new Vue({
    el: '#app',
    template: '<App/>',
    ponents: { App }
});
发布评论

评论列表(0)

  1. 暂无评论