墨香年少 32 发布于 2022年1月2日 import React, { Component } from 'react'; import PubSub from 'pubsub-js' import './navigation.css' const menuItems = [] class Navigation extends Component { constructor(props) { super(props); this.state = { width: 0, height: 0 }; this.updateWindowDimensions = this.updateWindowDimensions.bind(this); } componentDidMount() { this.updateWindowDimensions(); window.addEventListener('resize', this.updateWindowDimensions); } componentWillUnmount() { window.removeEventListener('resize', this.updateWindowDimensions); } updateWindowDimensions() { this.setState({ width: window.innerWidth, height: window.innerHeight }); console.info("window.innerWidth="+window.innerWidth) } render() { return ( <div id="header"> <div className='wrapper'></div> </div> ); } } export default Navigation; 目之所及,皆是回忆,心之所想,皆是过往 分享这篇帖子 链接帖子 分享到其他站点