Jquery validation plugin - TypeError: $(…).validate is not a function

后端 未结 8 1120
不知归路
不知归路 2020-12-01 08:45

My script throw errors:

TypeError: jQuery.validator is undefined additional-methods.js:20 TypeError: $(...).validate is not a function index.php:115

8条回答
  •  佛祖请我去吃肉
    2020-12-01 09:30

    If using VueJS, import all the js dependencies for jQuery extensions first, then import $ second...

    import "../assets/js/jquery-2.2.3.min.js"
    import "../assets/js/jquery-ui-1.12.1.min.js"
    import "../assets/js/jquery.validate.min.js"
    import $ from "jquery";
    

    You then need to use jquery from a javascript function called from a custom wrapper defined globally in the VueJS prototype method.

    This safeguards use of jQuery and jQuery UI from fighting with VueJS.

    Vue.prototype.$fValidateTag = function( sTag, rRules ) 
    {
        return ValidateTag( sTag, rRules );
    };
    
    function ValidateTag( sTag, rRules )
    {
        Var rTagT = $( sTag );
        return rParentTag.validate( sTag, rRules );
    }
    

提交回复
热议问题