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

Tabs组件可否对于标签页内内容进行预先加载 #1039

Closed
jin5354 opened this issue Feb 19, 2016 · 6 comments
Closed

Tabs组件可否对于标签页内内容进行预先加载 #1039

jin5354 opened this issue Feb 19, 2016 · 6 comments

Comments

@jin5354
Copy link

jin5354 commented Feb 19, 2016

使用Tabs组件时发现,默认Active以外的标签页只有在切换过去时才会被初始化和渲染。我有一个标签页内部存在一个Log组件,需要在最初既被加载,有没有办法实现预先加载?

DEMO: http://codepen.io/anon/pen/MKdEBP?editors=0011

  • The version of antd : 0.12.1
@afc163
Copy link
Member

afc163 commented Feb 22, 2016

目前的组件实现貌似暂时不支持。

你可以先这么做。

<Tabs defaultActiveKey="1" onChange={this.handleChange}>
  <TabPane tab="选项卡一" key="1" />
  <TabPane tab="选项卡二" key="2" />
  <TabPane tab="选项卡三" key="3" />
</Tabs>

<ul>
  {this.state.activeKey === '1' ? <li>选项卡内容一</li> : null}
  {this.state.activeKey === '2' ? <li>选项卡内容二</li> : null}
  {this.state.activeKey === '3' ? <li><Test /></li> : null}
</ul>

@afc163 afc163 closed this as completed Feb 24, 2016
@sethzhao
Copy link

遇到同样问题,用楼上的方法并不能行,问题还是一样的。

@sethzhao
Copy link

要把组件直接放出来,用activeKey来决定组件的display属性是block还是none才行。

@qubaomingg
Copy link

qubaomingg commented Sep 9, 2016

@slertness: @afc163 的方法思路可行,不过放三目运算符里面貌似不行,可通过visible属性来控制显隐

<Tabs defaultActiveKey="0" onChange={this.onToggleTab}>
{
    <Tabs.TabPane tab={'title1'} key={1} />
    <Tabs.TabPane tab={'title2'} key={2} />
}
</Tabs>
<SomeComponent visible={this.state.activeKey === 0}/>
<SomeComponent visible={this.state.activeKey === 1}/>

@XUGAOBO
Copy link

XUGAOBO commented Jun 16, 2017

受益匪浅,
其实也可以模拟切换页签的事件

@lock
Copy link

lock bot commented Jun 16, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants