[Vuejs]-How to pass a variable by prop and not allow child to change it ( vue 2 )

3👍

You can clone the prop value, with these methods:

  1. If the value is a simple data type (string, boolean, number):
this.mensagem = JSON.parse(JSON.stringify(this.mensagemEdit));
  1. If the value is a simple object:
this.mensagem = Object.assign({}, this.mensagemEdit);
  1. For more complex values (array of objects, nested objects) I suggest using lodash:
import { cloneDeep } from "lodash"

this.mensagem = cloneDeep(this.mensagemEdit);

Leave a comment