# wxml/no-index-in-wx-key

# Background

index

In a component, by binding an array using the wx:for control property, you can use the data of the array items to re-render this component.

The subscript variable name of the current item of the default array defaults to index, and the variable name of the current item of the array defaults to item.

Wechat Document Reference (opens new window)

# Motivation

This rule enforce developer use implicit wx:key

<!-- ✓ GOOD --> <view wx:for="{{goodsList}}" wx:key="goodsId" > {{item.name}} </view> <!-- ✗ BAD --> <view wx:for="{{goodsList}}" wx:key="index" > {{item.name}} </view>
Now loading...

💡 tips

You can edit code via online editor, it's online REPL, try to fix eslint problem !

# Config

No special options, normal config is ok

{ "wxml/no-index-in-wx-key": "error" }

# Version

This rule was introduced in eslint-plugin-wxml v0.2.1

# Implementation