Home » vue » Access to a object with refs

Access to a object with refs

Posted by: admin November 26, 2021 Leave a comment

Questions:

I want to access to a ref define with an id

:ref="'modal' + item.id"

it give me modal123456 when I console log it

In my function I have :

function(item) {
    console.log(this.$refs.modal + item)
// I want to have this.$refs.modal123456
}

how can I do it ?

Answers:

You are appending item to value, you should append it to property name instead:

console.log(this.$refs[`modal${item.id}`])