首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >v-model抱怨道具和数据

v-model抱怨道具和数据
EN

Stack Overflow用户
提问于 2018-11-01 08:20:10
回答 1查看 193关注 0票数 0

第一次修改Vue时,我得到了一个相当无害的输入,如下所示:

代码语言:javascript
复制
<input type="number" name="quantity" v-model="quantity" />

它存在于一个组件中。

prop对象上设置数量时,我得到以下错误(当更改输入中的值时):

代码语言:javascript
复制
Vue.component('my-product', {props: {quantity : {default: 1}}});

[Vue warn]: 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: "quantity"

但是,当按照Vue tutorial documentation上的演示在data对象上设置数量时,我得到以下错误:

代码语言:javascript
复制
Vue.component('my-product', {data: {quantity : 1}});

[Vue warn]: The "data" option should be a function that returns a per-instance value in component definitions.

我不知所措。此字段与父视图无关(vues?)因此,也许我只是误解了如何设置它。

EN

回答 1

Stack Overflow用户

发布于 2018-11-01 08:28:05

哦,它就在错误文本中...

代码语言:javascript
复制
Vue.component('my-product', {
  data: function(){ 
      return {quantity : 1}
  }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53093624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档