首页 > 解决方案 > 未指定任何元素来初始化 Windows 上的 PerfectScrollbar

问题描述

我在 react js 的服务器启动时收到此错误。

错误:没有指定元素来初始化 PerfectScrollbar

但是它在 Ubuntu 操作系统上运行良好。我正在使用窗户。

提前致谢

这是相关代码

// creates a beautiful scrollbar
import PerfectScrollbar from "perfect-scrollbar";
import "perfect-scrollbar/css/perfect-scrollbar.css";
// ref to help us initialize PerfectScrollbar on windows devices
  const mainPanel = React.createRef();

const useStyles = makeStyles(styles);

  // initialize and destroy the PerfectScrollbar plugin
  React.useEffect(() => {
    if (navigator.platform.indexOf("Win") > -1) {
      ps = new PerfectScrollbar(mainPanel.current, {
        suppressScrollX: true,
        suppressScrollY: false,
      });
      document.body.style.overflow = "hidden";
    }
    window.addEventListener("resize", resizeFunction);
    // Specify how to clean up after this effect:
    return function cleanup() {
      if (navigator.platform.indexOf("Win") > -1) {
        ps.destroy();
      }
      window.removeEventListener("resize", resizeFunction);
    };
  }, [mainPanel]);


  

标签: reactjsperfect-scrollbar

解决方案


推荐阅读