React 中的 Jquery 未定义 [英] Jquery in React is not defined

查看:43
本文介绍了React 中的 Jquery 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想接收ajax请求,但问题是在React中没有定义jquery.React 版本是 14.0

Hi I just want to receive ajax request, but the problem is that jquery is not defined in React. React version is 14.0

 Uncaught ReferenceError: $ is not defined

我有两个文件 :

import React from 'react'; 
import { render } from 'react-dom';
import App from './containers/App';  

const root = document.getElementById('root');  

render( 
  <App source='https://api.github.com/users/octocat/gists' />, 
  root
);

app.js

import React, { Component } from 'react';

export default class App extends Component {

    componentDidMount() {
        const { source } = this.props;

        console.log($); // throws error
    }

    render() {
        return (
            <h1>Hey there.</h1>
        );
    }
}

推荐答案

尝试将 jQuery 添加到您的项目中,例如

Try add jQuery to your project, like

npm i jquery --save

或者如果你使用凉亭

bower i jquery --save

然后

import $ from 'jquery'; 

这篇关于React 中的 Jquery 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆