0👍
To set a dynamic key name on an object in javascript, it turns out you can use square brackets, as in:
{
[keyName] : value
}
So my code is fixed by simply passing the prop as the key in the axios call:
submit() {
axios
.post(`/admin/${this.userId}/update`, {
[this.$props.field]: this.value
})
.then(response => {
// we out here
});
}
- [Vuejs]-Toggle Other Elements in VueJS
- [Vuejs]-My Vue CDN code is not working, my output says {{ name }}
Source:stackexchange.com