gpt4 book ai didi

javascript - React 中的 Jquery 未定义

转载 作者:IT王子 更新时间:2023-10-29 03:00:34 25 4
gpt4 key购买 nike

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

错误信息

 Uncaught ReferenceError: $ is not defined

我有两个文件:

index.js

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 添加到您的项目中,例如

npm i jquery --save

或者如果你使用 bower

bower i jquery --save

然后

import $ from 'jquery'; 

关于javascript - React 中的 Jquery 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33351288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com