0

I would like to access the ref of input, but still getting undefined.

// sample in template template:

<input type="text" class="form-control form-control-sm" v-bind:value=meminfo.last_name name="online_membership[last_name]" ref="online_membership[last_name]" >

Script:

methods() {
   function() {
     // i would like to access the input value of this ref
     this.$refs.online_membership[last_name]
   }
}
painotpi
  • 6,894
  • 1
  • 37
  • 70

1 Answers1

0

you should change something like below:

best practice:

// sample in template template:

<input type="text" class="form-control form-control-sm" v-bind:value=meminfo.last_name name="online_membership[last_name]" :ref="online_membership[last_name]" >

Script:

methods() {
   function() {
     // i would like to access the input value of this ref
     this.$refs[online_membership[last_name]]
   }
}

but still if you want to use as a string including '[' then simply you can use below solution:

// sample in template template:

<input type="text" class="form-control form-control-sm" v-bind:value=meminfo.last_name name="online_membership[last_name]" ref="'online_membership[last_name]'" >

Script:

methods() {
   function() {
     // i would like to access the input value of this ref
     this.$refs['online_membership[last_name]']
   }
}

hope it will solve your problem

Mahamudul Hasan
  • 2,745
  • 2
  • 17
  • 26