如何在计算 属性 VUEjs 中设置整个对象

How set entire object in computed property VUEjs

我的问题是我有一个计算 属性 和 setter 和 getter 像:

computed:{
        dataComputed:{
            get: function () {  return  this.dataProps},
            set: function (newValue) {
               //here my problem
                this.dataProps= Object.assign({}, newValue);
            }

        }
    },

但我的问题是我会分配从 ajax 调用中检索到的整个对象,例如:

var vm = this;
axios.post('/route', { data:this.dataComputed})
   .then(function (response) {
      vm.dataComputed = response.data.newData;
   }).catch(function (error) {});

但在控制台中我有这个警告:

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "dataProps"

如何将从后端检索到的整个对象分配给计算对象?

根据您收到的错误消息,dataProps 似乎是您组件的 属性,并且属性无法更改。尝试将 Object.assign({}, newValue); 分配给 data 变量而不是 props.

中的变量