简体   繁体   English

调用彼此函数的Create-react-app javascript无法正常工作

[英]Create-react-app javascripts calling each others' functions not working

I am learning React.js with the create-react-app framework. 我正在使用create-react-app框架学习React.js。

I need to use a readymade admin template which has javascript files calling other JS files' modules. 我需要使用现成的管理模板,该模板具有调用其他JS文件模块的javascript文件。

eg In App.js I have: 例如在App.js中,我有:

1. import $ from 'jquery'
2. import Layout from './css/layout.min.js'
3. import Navbar from './js/navbar.min.js'

In navbar.min.js, I am getting an error: 在navbar.min.js中,出现错误:

1. $ is not defined
2. Layout (a function of layout.min.js) is not defined

There are hundreds of such modules so manual import from each JS is not an option. 此类模块有数百个,因此不能选择从每个JS手动导入。

So far I've tried exporting $, Layout from App.js but no results. 到目前为止,我已经尝试从App.js导出$,Layout,但是没有结果。

Any help would be appreciated. 任何帮助,将不胜感激。

You should do ( id you didn't) 你应该做(你没有的身份证)

npm i jquery --save

And in your layout.min.js you should have export default . 并且在您的layout.min.js中,您应该具有export default

Btw, maybe it should be import Layout from './js/layout.min.js'? 顺便说一句,也许它应该是import Layout from './js/layout.min.js'?

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

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