如何在反应中删除数组选项卡中的聊天值

问题描述

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] : '/')

但它不起作用。每次我点击它都会推送一个值。

解决方法

你可以使用 splice

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)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...