React.js:使用React.js的jQuery自定义内容滚动条

编程入门 行业动态 更新时间:2024-10-10 17:29:23
本文介绍了React.js:使用React.js的jQuery自定义内容滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

im tryin在响应中集成Jquery自定义滚动条插件此处.这是我的代码

im tryin to integrate Jquery custom scrollbar plugin here in react. here is my code

import $ from "jquery"; import mCustomScrollbar from 'malihu-custom-scrollbar-plugin'; ..... componentDidMount: function() { // fixed sidebar var self = this; mCustomScrollbar($); $(ReactDom.findDOMNode(this.refs.menu_fixed)).mCustomScrollbar({ autoHideScrollbar: true, theme: 'minimal', mouseWheel:{ preventDefault: true } }); self.forceUpdate(); },

我收到此错误 index.jsx:51 Uncaught TypeError:(0,_malihuCustomScrollbarPlugin2.default)不是一个函数

有人可以帮助使它工作吗

did somebody can help to make it work thanks

推荐答案

这不是React错误.这是基于您的模块加载器(我猜是webpack?),将jQuery插件视为ES2015模块.尝试以CommonJS样式导入您的插件.换句话说,替换为:

That’s not a React error. That’s based on your module loader (webpack, I’m guessing?) treating the jQuery plugin as if it were an ES2015 module. Try importing your plugin in the CommonJS style. In other words, replace:

import mCustomScrollbar from 'malihu-custom-scrollbar-plugin';

具有:

var mCustomScrollbar = require('malihu-custom-scrollbar-plugin');

如果这不起作用,则需要共享有关模块加载器及其配置的更多信息.

If that doesn’t work, you will need to share more info about your module loader and its configuration.

也就是说,如 Toby 所述,尝试将jQuery插件与React组件结合通常是不可靠和棘手的,因此请继续小心.

That said, as Toby mentioned, trying to combine jQuery plugins with React components is often unreliable and tricky, so proceed with caution.

更多推荐

React.js:使用React.js的jQuery自定义内容滚动条

本文发布于:2023-10-10 09:38:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478310.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   滚动条   内容   React   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!