【问题标题】:Iterate on object迭代对象
【发布时间】:2019-12-06 14:45:56
【问题描述】:

我有一个这样的对象:

 obj: {
        'tags': {
                '0': 'One',
                '1': 'Two',
                '2': 'Three',
                '3': 'Four',
                '4': 'Five',
                '5': 'Six',
                }

我这样做:

<div
    v-for="(tag, index) in obj.tags">
    <v-text-field
     v-model="tag"

    >
    </v-text-field>
</div>

我想在 vuetify 文本字段中显示该值,但是当我执行 vfor 时,我收到以下消息:

<v-text-field v-model="tag">: You are binding v-model directly to a v-for iteration alias. This will not be able to modify the v-for source array because writing to the alias is like modifying a function local variable. Consider using an array of objects and use v-model on an object property instead.

我该怎么办?

【问题讨论】:

  • 你不能把那个对象转换成一个数组吗?

标签: javascript vue.js vuetify.js


【解决方案1】:

因为标签是您正在使用的对象的“别名”,我们无法通过该别名引用它。

但是,我们可以使用 v-for 中的索引将其重新绑定到原始对象。

这将为你绑定它。

<v-text-field v-model="obj.tags[index]">    
</v-text-field>

【讨论】:

  • 那不行,如果可能的话我还需要一个v-model,因为我必须在之后编辑名称
  • 对不起,我想我误解了这个问题,但我想我现在明白你的意思了。让我帮你看看:)
猜你喜欢
  • 2019-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-28
  • 1970-01-01
相关资源
最近更新 更多