json数据
[
{
"name": "外观",
"value": [
"白色",
"蓝色",
"红色"
],
"attr_val_input": ""
},
{
"name": "尺码",
"value": [
"39",
"40",
"41",
"42",
"43"
],
"attr_val_input": ""
}
]
}
这里的item.value 数据是上面json数据中value
代码:
<span v-for="(vItem,vIndex) in item.value" :key="vIndex">
<InputTag v-model="vItem" style="margin-right: 10px" closable @close="handleAttrValClose(index,vIndex)">{{ vItem }}</InputTag>
</span>
报错:
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
这个错误是由于在使用v-for循环做一些动态生成的事务时,v-model直接绑定了v-for中的迭代变量导致的
需要调整代码为如下才可以
<span v-for="(vItem,vIndex) in item.value" :key="vIndex">
<InputTag v-model="item.value[vIndex]" style="margin-right: 10px" closable @close="handleAttrValClose(index,vIndex)">{{ vItem }}</InputTag>
</span>
发布时间 : 2023-03-01,阅读量:1435