0

I was wondering if is possible to define method/property name from variable.

Code

events: {
  'reload:clients.client' () {
    this.load()
  }
},

I want to replace 'reload:clients.client' with a variable.

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
Vasil Atanasov
  • 165
  • 1
  • 2
  • 12

1 Answers1

2

This should do the trick:

let name = 'reload.clients.client'

let data = {
    events: {
        [name]: () => {
            this.load()
        }
    }
}

console.log(data)
Spankied
  • 1,626
  • 13
  • 21