0
tabs: [ '/home', '/about', '/chat' ];

<ResponsiveNav ppearance="subtle" justified
                  removable
                  moreText={<Icon icon="more" />}
                  moreProps={{ noCaret: true }}
                  activeKey={activePage['link']}
                  onSelect={onSelectTab}
                  onItemRemove={eventKey => {
                    console.log(eventKey)
                  }}>
                  {tabs.map(tab => {
                    const menu = menus.find(a => a.link === tab);
                    return <ResponsiveNav.Item key={menu ?.key} eventKey={tab}> {menu ?.label}</ResponsiveNav.Item>
                  })}
                </ResponsiveNav>

如何'/chat'从选项卡中删除值。我试过的是我在onItemRemove

  const tabList = [...tabs]
                  tabList.splice(
                    tabList.map(item => item).indexOf(eventKey),
                    1
                  );

                  tabs.push(...tabList)

                  router.push(tabList[0] ? tabList[0] : '/')

但它不起作用。每次我单击它时,都会不断推送一个值。

4

1 回答 1

1

你可以使用拼接

const sample = ['/home', '/about', '/chat']
const index = sample.indexOf('/chat') // get index here

sample.splice(index,1) // delete one element at (index)
console.log(sample)

于 2021-03-05T07:59:07.033 回答