[Vuejs]-Pass a dynamic string value to vuelidate $v object – Vue

0👍

Given you asked this 9 months ago, you’ve probably figured it out already. But just in case anyone else bumps into the question…

You can specify the property key (i.e. the name of the property on the $v object as a string) using bracket notation.

Simply do this.$v[appliance].required instead of this.$v.appliance.required.

Bracket notation looks up the property by key name (your appliance string) on the object ($v), whereas dot notation looks for the actual property (appliance) on the parent object ($v).

Need a bit more info? The property accessors page on the Mozilla site will give you more details.

Leave a comment