1、安装
yarn add better-scroll
2、引用
import BScroll from 'better-scroll'
3、请求完数据后初始化
componentDidMount() {
const { dispatch } = this.props;
dispatch({
type: 'user/fetchUserData',
payload: localStorage.getItem('userid'),
callback: (res) => {
this.setState({
level: res.data.integral,
bScroll: new BScroll(this.wrapper, {probeType: 3, scrollX: false,scrollY: true,click: true})
})
}
});
}
4、组件结构样式
<div id="wrapper" className={styles.user_wrapper} ref={el => this.wrapper = el}>
<div className={styles.user_content}>
<div className={styles.home_top}>
</div>
</div>
</div>
.user_wrapper{
height: 100%;
overflow: hidden;
.user_content{
min-height: 100%;
}
}