美文网首页
v-for 循环时直接使用v-model绑定value报错

v-for 循环时直接使用v-model绑定value报错

作者: 努力与幸运 | 来源:发表于2020-12-01 08:52 被阅读0次

报错:'.sync' modifiers cannot update the iteration variable 'interfaceItem' itself.
将v-model直接绑定v-for的循环别名,会报错,因为这样绑定无法修改v-for源数组因为写入别名就跟修改函数形参一样。考虑使用一个对象数组并在对象属性上使用v-model。
可以通过index下标来引用所需数据,达到相同的目的。

<el-card
            v-for="(interfaceItem, index) in modelInterfaceForm.interfaces"
            class="m-bottom-10 card-storage"
            :key="index"
          >
            <hc-modify-vm-netcard
              :create-vm="true"
              :interface-item.sync="modelInterfaceForm.interfaces[index]"
            ></hc-modify-vm-netcard>
</el-card>

相关文章

网友评论

      本文标题:v-for 循环时直接使用v-model绑定value报错

      本文链接:https://www.haomeiwen.com/subject/rfmjwktx.html