Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

列表加上key顺序变化时,部分列表项点击事件失效 #7227

Closed
vdfor opened this issue Aug 1, 2020 · 1 comment · Fixed by #7968
Closed

列表加上key顺序变化时,部分列表项点击事件失效 #7227

vdfor opened this issue Aug 1, 2020 · 1 comment · Fixed by #7968
Assignees
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Milestone

Comments

@vdfor
Copy link
Contributor

vdfor commented Aug 1, 2020

相关平台

微信小程序

复现仓库

https://github.com/vdfor/taro-issue-demo-005
小程序基础库: 2.12.0
使用框架: React

复现步骤

最小化仓库运行后,点击改变数据按钮,点击 第一行,从控制台可以看到此时点击事件执行了;点击 第二行/第三行,发现点击事件未执行。

此时,如果使用index作为key,则点击事件均有效。

主要复现代码:

import React, { FC, useState } from 'react'
import { View, Button } from '@tarojs/components'
import './index.scss'

const Index: FC = () => {
  const [list, setList] = useState(['张三', '李四', '王二', '赵五', '王六']);
  const changeList = () => {
    setList(['王六', '王二', '赵五'])
  }
  return (
    <View>
      <Button onClick={changeList}>改变数据</Button>
      <View className='list'>
        {list.map(i => (
          <View
            className='list-item'
            key={i}
            onClick={() => {
              console.log('item click', i)
            }}
          >
            {i}
          </View>
        ))}
      </View>
    </View>
  )
}

export default Index;

期望结果

列表加上key顺序变化时,所有列表项点击事件均可执行。

实际结果

列表加上key顺序变化时,部分列表项点击事件失效

环境信息

Taro CLI 3.0.6 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 12.18.2 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.4 - C:\Users\vdfor\AppData\Roaming\npm\yarn.CMD
      npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
@moonkop
Copy link

moonkop commented Sep 4, 2020

#6983 也是这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
5 participants