{"record":{"id":"c37c50790c6f13bd","repo":"Meituan-Dianping/mpvue","slug":"v-for-arr","errorCode":null,"errorMessage":"同一组件内嵌套的 v-for 不能连续使用相同的索引，目前为: ${arr}","messagePattern":"同一组件内嵌套的 v-for 不能连续使用相同的索引，目前为: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/platforms/mp/compiler/mark-component.js","lineNumber":20,"sourceCode":"\nfunction maybeTag (tagName) {\n  return convertTagMap[tagName]\n}\n\nfunction getWxEleId (index, arr) {\n  if (!arr || !arr.length) {\n    return `'${index}'`\n  }\n\n  const str = arr.join(`+'-'+`)\n  return `'${index}_'+${str}`\n}\n\n// 检查不允许在 v-for 的时候出现2个及其以上相同 iterator1\nfunction checkRepeatIterator (arr, options) {\n  const len = arr.length\n  if (len > 1 && len !== new Set(arr).size) {\n    options.warn(`同一组件内嵌套的 v-for 不能连续使用相同的索引，目前为: ${arr}`, false)\n  }\n}\n\nfunction fixDefaultIterator (path) {\n  const { for: forText, iterator1 } = path\n  if (forText && !iterator1) {\n    path.iterator1 = 'index'\n  }\n}\n\nfunction addAttr (path, key, value, inVdom) {\n  path[key] = value\n  path.plain = false\n  // path.attrsMap[key] = value\n  if (!inVdom) {\n    path.attrsMap[`data-${key}`] = `{{${value}}}`\n  }\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/src/platforms/mp/compiler/mark-component.js#L2-L38","documentation":"uni-app's mini-program compiler (mark-component) checks nested v-for inside the same component. If two or more nested v-for directives use the same iterator variable name (e.g., both `item in a` with `index` as iterator1), the compiled scoping would collide, so the compiler emits this custom Chinese warning.","triggerScenarios":"Nested `<view v-for=\"(a, i) in list1\"><view v-for=\"(b, i) in list2\">` — the inner v-for reuses the same index variable `i` as the outer one within one component.","commonSituations":"Copy-pasted nested list templates; nested tables/grids iterating rows and columns with the same index name; converting web Vue templates that tolerated shadowing into mp templates where the compiler forbids it.","solutions":["Rename the inner v-for index to a unique name (e.g. `j` or `innerIndex`)","Also make item variable names unique between nested loops to avoid shadowing","If lists are deeply nested, consider flattening data or splitting into child components"],"exampleFix":"// before\n<view v-for=\"(row, i) in rows\">\n  <view v-for=\"(col, i) in row.cols\">{{ col }}</view>\n</view>\n// after\n<view v-for=\"(row, i) in rows\">\n  <view v-for=\"(col, j) in row.cols\">{{ col }}</view>\n</view>","handlingStrategy":"validation","validationCode":"function assertUniqueIterators (vForStack) {\n  const seen = new Set()\n  vForStack.forEach(f => {\n    if (seen.has(f.iterator1)) throw new Error('duplicate v-for index: ' + f.iterator1)\n    seen.add(f.iterator1)\n  })\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always name nested v-for indexes uniquely (i, j, k)","Also unique-ify item variable names across nesting levels","Lint templates for shadowed loop variables","Split deeply nested lists into child components"],"tags":["v-for","compiler","mini-program","scope"],"backgroundTag":"duplicate-v-for-iterator","analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}