Skip to content

Commit

Permalink
add wx:key=index
Browse files Browse the repository at this point in the history
  • Loading branch information
wenwenhua committed Dec 2, 2024
1 parent e0d0ba4 commit acbd41e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export default function directiveHelperMixin () {
return {
methods: {
__getWxKey (item, key) {
__getWxKey (item, key, index) {
if (key === 'index') {
return index
}
return key === '*this' ? item : item[key]
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/template-compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ function postProcessFor (el) {
function postProcessForReact (el) {
if (el.for) {
if (el.for.key) {
addExp(el, `this.__getWxKey(${el.for.item || 'item'}, ${stringify(el.for.key)})`, false, 'key')
addExp(el, `this.__getWxKey(${el.for.item || 'item'}, ${stringify(el.for.key)}, ${el.for.index || 'index'})`, false, 'key')
addAttrs(el, [{
name: 'key',
value: el.for.key
Expand Down

0 comments on commit acbd41e

Please sign in to comment.