我试图使用我的标题中的链接滚动到我的应用程序的不同部分与scrollIntoView.标题是App的孩子.我收到一个TypeError说我试图保存id的变量是未定义的.有人可以帮我确定我做错了什么吗?我想我可能不得不使用ComponentDidMount,但我不知道该怎么做,如果这甚至是修复.我将不得不用我的所有标题链接执行此操作.
// ERROR bundle.js:152 Uncaught TypeError:无法在atClick(bundle.js:19957)的Object.actScrollLocations(bundle.js:152)处读取属性'scrollIntoView'为null.在Object.ReactErrorUtils.invokeGuardedCallback(bundle.js: 4660)在executeDispatch(bundle.js:4460)的executeDispatch(bundle.js:4483),executeDispatchesAndRelease(bundle.js:3913),executeDispatchesAndReleaseTopLevel(bundle.js:3924),位于forEachAccumulated(bundle.forEach)的executeDispatchesAndReleaseTopLevel(bundle.js:3924) .js:4760)at Object.processEventQueue(bundle.js:4129)///////
//应用
class App extends Component {
constructor(props) {
super(props);
this.closeModal = this.closeModal.bind(this);
this.openModal = this.openModal.bind(this);
this.getScrollLocations = this.getScrollLocations.bind(this);
this.state = {
open: false,
projects: Service,
selectedProject: Service[0]
}
}
closeModal(event) {
this.setState({open: false});
}
openModal(project) {
this.setState({
open: true,
selectedProject: project
});
}
///////////// scroll function //////////////
getScrollLocations() {
const whatIDo = document.getElementById('.whatIdo');
console.log(whatIDo)
whatIDo.scrollIntoView();
}
render() {
const show = {
display: 'block'
};
const hide = {
display: 'none' …
Run Code Online (Sandbox Code Playgroud)