My goal is to define my rules once and then reuse them for all of my fields. To do this, I need to pass extra parameters to my rules, like maxlength of 20 on one v-text-field, but a maxlength of 50 on another. From what I see, only the value is getting passed. How can I add extra parameters to my rules?
<template>
<v-input :rules=[rules.max(20)] v-model="field1" />
<v-input :rules=[rules.max(50)] v-model="field2" />
</template>
<script>
data() {
rules: {
max(v, maxnum) { //maxnum is the parameter I want to add so that I can pass different values and reuse the same rule on multiple fields
return (v || '').length <= maxnum || 'Max exceeded';
}
}
}
</script>