I have a vue form and I am trying gather the data into an object, But when one object element is empty then Id want that field to be destroy'd.
this is my input field:
<input v-model="fields.title" >
my data:
data() {
return {
fields: {},
}
},
Basically right now what happens, is when I write something in my field, it creates title: 'data' and if i delete the text inside then that element still exists there so I am left with title: '', but I want it to be deleted if its empty.
I can recreate this like this:
computed: {
destroyFieldWhenEmpty() {
if (this.fields.title === ''){
this.$delete(this.fields, 'title')
}
But now If i have a lot of fields, I have to re-write that if statement for each input.
Thus, How could i go by doing this better?
destroyFieldWhenEmptyis a misuse of computed props, as it's seemingly used only to deletefields.title, but computed props are supposed to return something (to be used elsewhere in the component) and should not have side effects.