[Vuejs]-How to create computed properties with Typescript in Vuejs

0👍

As of for Vue you should never have to mutate a prop (which has been passed to a child component through the parent), because whatever you do within the child component – the parent can always change and overwrite the props value (as already stated in the error message).

To mutate a passed in prop you have to define a locally used one in your child component. In your case this can be done by a computed property which just returns a newly created array depending on your prop.

computed: {
    elements() {
        return [...this.dataElements]
    }
}

Any change on the array should always be reported to the parent, by emitting an event, which at the end will handle the appropriate mutation and pass the prop back again to the child.

Leave a comment