Skip to content

Commit dc1a9fc

Browse files
committed
fix: 修复页面跳转和循环key重复问题
1 parent 22ca02c commit dc1a9fc

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/pages/basic/color/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,11 @@ export default class BasicColor extends React.Component<{}, BasicColorState> {
148148
<View className='panel__title'>{item.type}</View>
149149
<View className='panel__content'>
150150
<View className='color-list'>
151-
{item.data.map(color => (
152-
<View className='color-item' key={color.hex}>
151+
{item.data.map((color: Color, index: number) => (
152+
<View
153+
className='color-item'
154+
key={`color-${color.hex}-${index}`}
155+
>
153156
<View
154157
className='color-item__circle'
155158
style={`background: ${color.hex}`}

src/pages/panel/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react'
22
import { Image, Text, View } from '@tarojs/components'
3-
import { CommonEvent } from '@tarojs/components/types/common'
43
import Taro from '@tarojs/taro'
54
import iconAction from '../../assets/images/icon-list-action.png'
65
import iconBasic from '../../assets/images/icon-list-basic.png'
@@ -297,8 +296,7 @@ export default class PanelBasic extends React.Component<{}, PanelBasicState> {
297296
})
298297
}
299298

300-
private gotoComponent = (e: CommonEvent): void => {
301-
const { id, parent } = e.currentTarget.dataset
299+
private gotoComponent(id: string, parent: string): void {
302300
Taro.navigateTo({
303301
url: `/pages/${parent.toLowerCase()}/${id.toLowerCase()}/index`
304302
})
@@ -332,9 +330,7 @@ export default class PanelBasic extends React.Component<{}, PanelBasicState> {
332330
<View
333331
className='component-list__item'
334332
key={item.id}
335-
data-id={item.id}
336-
data-parent={currentId}
337-
onClick={this.gotoComponent}
333+
onClick={this.gotoComponent.bind(this, item.id, currentId)}
338334
>
339335
<Text className='name'>{`${item.id} ${item.name}`}</Text>
340336
<Text className='at-icon at-icon-chevron-right' />

0 commit comments

Comments
 (0)