I am trying to access a DOM element with Vue, using the $refs functionality, but I am having trouble getting it to work.
My element looks like so below. The plateId is generated dynamically, so it will not always be the same number:
<textarea :ref="plateId + '-notes'">
My Vue function looks like so:
/* This does not work */
addNotes: function(plateId) {
console.log(this.$refs.plateId + '-notes');
}
Whenever I run this code and the function is activated, it just reads undefined in my console. I've also tried this, which also does not work and reads undefined:
/* This does not work */
addNotes: function(plateId) {
var plateIdNotes = plateId + '-notes';
console.log(this.$refs.plateIdNotes);
}
Replacing var with const (I am using ES6 and transpiling the code) doesn't work either:
/* This does not work */
addNotes: function(plateId) {
const plateIdNotes = plateId + '-notes';
console.log(this.$refs.plateIdNotes);
}
I know the ref is binding correctly to the element, because when I do this below, I can see all of my other refs in the console, as well as the plateId-notes ref:
/* This works */
addNotes: function(plateId) {
console.log(this.$refs);
}
How can I access the plateId ref using the parameter in my function?