[Vuejs]-Vuejs pass extra parameter to function

1👍

You have to define your rule as function in your rules array, first lets update your validation function to accept second argument, I will also set it to default value of 2:

    const isCheckLimit = (v, minLength = 2) => {
      return v.length > minLength || t('checked-to-much');
    };

Now if you use this for your rules:

  :rules="[(value) => isCheckLimit(value, 4)]"

Your validation function will use 4 for minLength instead of default 2.

Original way will also work:

  :rules="[isCheckLimit]"

But will use the default value of 2 for minLength

Leave a comment