gpt4 book ai didi

laravel - 如何避免vue中的 react 性

转载 作者:行者123 更新时间:2023-12-04 18:18:13 31 4
gpt4 key购买 nike

我正在将一个对象从属性“模型”(我从 Laravel 中的 Blade 属性模型中获得)分配给数据属性模型。后来数据属性模型发生变化,因为它绑定(bind)到表单输入字段。但 Prop “模型”也发生了变化。它们是同一个对象。我怎样才能避免这种行为?我需要属性“模型”保持安装时的状态。我在 created() 方法和 data() 中尝试了这个:

 Vue.set(this, 'model', this.transferredData.model);

那没有帮助

最佳答案

您可以使用spread syntax创建一个新对象,因此它只会改变新创建的对象。

Vue.set(this, 'model', {...this.transferredData.model});
// or Vue.set(this, 'model', Object.assign({}, this.transferredData.model));

注意:如果它是嵌套的,那么您必须递归解构,或者您可以使用:
Vue.set(this, 'model',JSON.parse(JSON.stringify(this.transferredData.model)))

关于laravel - 如何避免vue中的 react 性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59214566/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com