无法导入在反应中使用jQuery的js文件

时间:2019-02-16 19:47:12

标签: jquery reactjs

我的jsx文件已导入:

import React, {Component} from 'react';
import {BrowserRouter as Router, Route, Link} from "react-router-dom";
import $ from 'jquery'
import './App.css';
import './dashboard/css/application.css'
import './dashboard/css/docs.css'
import './dashboard/css/toolkit.css'
import './dashboard/js/application.js'
import './dashboard/js/toolkit.js'
import './dashboard/js/chart.js'

toolkit.js使用jQuery$名称:

if (typeof jQuery === 'undefined') {
  throw new Error('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.')
}

+function ($) {
  var version = $.fn.jquery.split(' ')[0].split('.')
  if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] >= 4)) {
    throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0')
  }
}(jQuery);

但是React显示错误:

 Line 10:     Expected an assignment or function call and instead saw an expression  no-unused-expressions
  Line 15:     'jQuery' is not defined                                                no-undef
  Line 18:     Expected an assignment or function call and instead saw an expression  no-unused-expressions
  Line 167:    '$' is not defined                                                     no-undef

我什至尝试将jquery连接到<head>标记:

<script
        src="https://code.jquery.com/jquery-3.3.1.min.js"
        integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
        crossorigin="anonymous"></script>

如何使toolkit.js工作?哪种方法是连接jquery的正确方法?

0 个答案:

没有答案