【发布时间】:2020-12-20 08:34:56
【问题描述】:
在开发我的 react 应用时遇到同样的问题。所以我已经使用这样的命令导入 JQuery
npm install jquery
后来我从网站下载了一个 js min 文件,
您可以在顶部找到它。它命名为 jquery.loupe.min.js。所以我复制了它,并在src文件夹中创建了我自己的js文件。
在我的标题中,我包含了所有的文件:
import $ from 'jquery';
import './jquery.loupe.min.js'
在我的函数中,我尝试调用循环:
if (this.props.activeItem === "Loop") {
$('graph').loupe();
//window.$ = window.jQuery = require('jquery')
//window.$('graph').loupe();
}
我认为第二行和第三行应该可以工作,但结果相同。没有错误,但什么也没有。 我的 window$ 的 console.log
content.js?5f7c:406 ƒ ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
// Need init if jQuery is called (just allow error to be thrown if not included)
return new jQuery…
所以在我的渲染方法中,我有一个我想用循环连接的画布:
<div className="canvas">
<canvas
id="graph"
className="canvas-actual"
width="800px"
height="480px"
ref={this.canvasRef}
onMouseDown={this.handleMouseDown}
onMouseMove={this.handleMouseMove}
onMouseUp={this.handleMouseUp}
>
</canvas>
什么都没发生。没有错误或警告。 我没有什么重要的想法。谢谢。 代码(需要python2)
【问题讨论】:
-
如果你注意到代码,问我
-
不要查询 dom 使用 React API 和 ref。顺便说一句,当你有 React 时,你真的不应该使用 jquery。
-
我愿意,它给我一个错误 Uncaught TypeError: Cannot define property jQuery351064704862672539812, object is not extensible
-
真的不推荐在react中使用jQuery,如果想要react中的放大镜效果可以参考这个answer
标签: javascript jquery reactjs loops