[Vue warn]: Computed property “totalPrice“ was assigned to but it has no setter.

350 阅读1分钟

问题:

在Vue项目中出现如下错误提示:

[Vue warn]: Computed property "totalPrice" was assigned to but it has no setter.  (found in )

代码

<input v-model="totalPrice" />

原因:

v-model命令,因Vue 的双向数据绑定原理 , 会自动操作 totalPrice, 对其进行set 操作 而 totalPrice 作为计算属性,默认情况下,只能获取值 , 不能设置它的值

解决方案:

1. 计算属性,最好不直接和命令使用,进行修改

  1.  对 totalPrice 进行修改,让它支持 set 操作

代码如下:

computed: {
   totalPrice : {
        getfunction () {
            return this.money;
         },
       setfunction (newValue) {
           this.money = newValue;
       }
    }
}

作者:doubleyong

公众号:bug收集

博客:bugshouji.com (专门解决与收集bug的网站)

如果喜欢这篇文章,可以支持一下哟,分享、点赞、在看 走一个,哈哈@_@ '公众号'