加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在react.js中滚动到页面顶部

发布时间:2020-12-15 06:30:05 所属栏目:百科 来源:网络整理
导读:我有一个问题,我没有想法,如何解决。 在我的反应组件中,我显示了一长串数据,底部链接很少。 点击任何链接后,我填写新的链接集合列表,需要滚动到顶部。 问题是 – 如何在呈现新集合后滚动到顶部? 'use strict';// url of this component is #/:checkli
我有一个问题,我没有想法,如何解决。
在我的反应组件中,我显示了一长串数据,底部链接很少。
点击任何链接后,我填写新的链接集合列表,需要滚动到顶部。

问题是 – 如何在呈现新集合后滚动到顶部?

'use strict';

// url of this component is #/:checklistId/:sectionId

var React = require('react'),Router = require('react-router'),sectionStore = require('./../stores/checklist-section-store');


function updateStateFromProps() {
  var self = this;
  sectionStore.getChecklistSectionContent({
    checklistId: this.getParams().checklistId,sectionId: this.getParams().sectionId
  }).then(function (section) {
    self.setState({
      section,componentReady: true
    });
  });

    this.setState({componentReady: false});
 }

var Checklist = React.createClass({
  mixins: [Router.State],componentWillMount: function () {
    updateStateFromProps.call(this);
  },componentWillReceiveProps(){
    updateStateFromProps.call(this);
   },render: function () {
  if (this.state.componentReady) {
    return(
      <section className='checklist-section'>
        <header className='section-header'>{ this.state.section.name }   </header>
        <Steps steps={ this.state.section.steps }/>
        <a href=`#/${this.getParams().checklistId}/${this.state.section.nextSection.Id}`>
          Next Section
        </a>
      </section>
    );
    } else {...}
  }
});

module.exports = Checklist;
最后我用:
componentDidMount () {
  window.scrollTo(0,0)
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读