doubleyong
管理员
管理员
  • 最后登录2026-05-25
  • 发帖数1198
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:5760回复:0

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

楼主#
更多 发布于:2020-12-07 16:53
问题:在Vue项目中出现如下错误提示:
[Vue warn]: Computed property "totalPrice" was assigned to but it has no setter.  (found in <Anonymous>)

代码:
&lt;input v-model="totalPrice" /&gt;


原因:


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




解决方案:


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


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


代码如下:
computed: {
   totalPrice : {
        get: function () {
            return this.money;
         },
       set: function (newValue) {
           this.money = newValue;
       }
    }
}


   
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号