Vue2.* computed property ' ' was assigned to but it has no setter.

场景

父组件传递了一个属性给子组件,子组件需要在完成某个动作之后,修改这个动作。当我将这个计算属性在computed处理后, 再次修改的时候,会有警告而且修改没有成功 computed property 'count_format' was assigned to but it has no setter.

分析

count_format属性,如果没有设置 setter,也就是传入的是一个函数,或者传入的对象里没有 set 属性,当你尝试直接该改变这个这个计算属性的值,都会报这个错误。

解决

. 直接赋值给data变量,然后直接修改这个变量
        props: ['id', 'type', 'count'],
        data: function () {
            return {
                body: '',
                success_status: false,
                comments : [],
                count_format : this.count
            };
        },

猜你喜欢

转载自blog.csdn.net/cominglately/article/details/81063065