0

This is my code:

axios.post(currentUrl + this.data_source_url + "/create", {
    'date': this.item_data.date,
    'type_id': this.item_data.type_id,
    'value': this.item_data.value,
     this.id_name: this.id,  <------
    '_method': 'post',
});

I tried 'String text ${expression}' but this didn't work

Is it possible to use the this.id_name variable as a string in this axios call

Juve
  • 10,584
  • 14
  • 63
  • 90
elias.xe
  • 57
  • 7

1 Answers1

0

You can use a computed property name:

axios.post(currentUrl + this.data_source_url + '/create', {
  date: this.item_data.date,
  type_id: this.item_data.type_id,
  value: this.item_data.value,
  [this.id_name]: this.id, // <------
  _method: 'post'
})
CherryDT
  • 25,571
  • 5
  • 49
  • 74