简体   繁体   English

使用带有反应的 jquery 插件时导入错误

[英]error with imports when using jquery plugin with react

I am trying to use jquery.infinitedrag to create a component in react.我正在尝试使用 jquery.infinitedrag 在反应中创建一个组件。 My code is here:我的代码在这里:

//Grid.js

import React from 'react'
import './jquery/jquery.min.js'
import './jquery/jquery-ui.min.js'
import './jquery/jquery-ui.min.css'
import './jquery/jquery.infinitedrag.js'

export default class Grid extends React.Component{

    componentDidMount() {
        $.infinitedrag("wall")
    }

    render() {
        return(
            <div id="wall"/>
        )
    }
}

This is supposed to work by making a div (identified by id) when react renders and then filling in an infinite grid later once the component mounts.这应该通过在反应渲染时制作一个 div(由 id 标识)然后在组件安装后填充无限网格来工作。 The problem is, for some reason, jquery.infinitedrag is getting confused.问题是,出于某种原因,jquery.infinitedrag 变得混乱了。 Here is the error:这是错误:

Failed to compile.

./src/jquery/jquery.infinitedrag.js
  Line 108:4:  Expected an assignment or function call and instead saw an expression  no-unused-expressions
  Line 277:4:  'jQuery' is not defined                                                no-undef

My file structure looks like this:我的文件结构如下所示:

src
  -jquery
    -jquery.min.js
    -jquery-ui.min.js
    -jquery-ui.min.css
    -jquery.infinitedrag.min.js
  -Grid.js
  -misc other components and stuff

I am fairly new to javascript, so this is probably something dumb.我是 javascript 的新手,所以这可能有些愚蠢。

npm install jquery OR npm update to remove the second error. npm install jquerynpm update以消除第二个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM