英文:
React - integrate custom Bootstrap theme
问题
我已经尝试了几天来将一个简陋的Bootstrap
主题模板集成到一个React
应用中,但没有成功。
因此,我在我的文件夹中创建了一个新的应用程序。一切都很好。安装了主题所需的所有包并升级到最新版本。一切都很好。
现在,让我们使用一些自定义代码来自定义React中的App.js
组件:
function App() {
return (
<div className="App">
<section className="slice slice-lg delimiter-top delimiter-bottom">
<div className="container">
<div className="row mb-6 justify-content-center text-center">
<div className="col-lg-8 col-md-10">
<span className="badge badge-primary badge-pill">
What we do
</span>
<h3 className="mt-4">
Leading digital agency for <span className="text-warning typed" id="type-example-1" data-type-this="business, modern, dedicated"></span> solutions
</h3>
</div>
</div>
<div className="row row-grid">
<div className="col-md-4">
<div className="pb-4">
<div className="icon">
<img alt="Image placeholder" src="../../assets/img/svg/icons/Apps.svg" className="svg-inject img-fluid" />
</div>
</div>
<h5>Designed for developers</h5>
<p className="text-muted mb-0">Quick contains components and pages that are built to be customized and used in any combination.</p>
</div>
<div className="col-md-4">
<div className="pb-4">
<div className="icon">
<img alt="Image placeholder" src="../../assets/img/svg/icons/Ballance.svg" className="svg-inject img-fluid" />
</div>
</div>
<h5>Responsive and scalable</h5>
<p className="text-muted mb-0">Scalable and easy to maintain, Quick enables consistency while developing new features and pages.</p>
</div>
<div className="col-md-4">
<div className="pb-4">
<div className="icon">
<img alt="Image placeholder" src="../../assets/img/svg/icons/Book.svg" className="svg-inject img-fluid" />
</div>
</div>
<h5 className="">Very well documented</h5>
<p className="text-muted mb-0">No matter you are a developer or new to web design, you will find our theme very easy to customize with an intuitive code.</p>
</div>
</div>
</div>
</section>
</div>
);
}
export default App;
现在,让我们从index.js
中导入我们从自定义主题中需要的一切:
...
import './assets/css/quick-website.css';
import './assets/js/quick-website.js';
import './assets/libs/@fortawesome/fontawesome-free/css/all.min.css';
import './assets/libs/jquery/dist/jquery.min.js';
...
然而,当我导入主题的核心JS
文件(quick-website.js)时,我遇到了这些类型的错误:
- 来自
quick-website.js
- 来自
jquery.min.js
我在这里漏掉了什么?
英文:
I've been trying for couple days to integrate a poor Bootstrap
theme template in a React
app with no success.
So, I've created a new application in my folder. All good. Installed all the packages required by the theme and upgraded to the latest version. All good.
Now, let's customize the App.js
component in React with some custom code:
function App() {
return (
<div className="App">
<section className="slice slice-lg delimiter-top delimiter-bottom">
<div className="container">
<div className="row mb-6 justify-content-center text-center">
<div className="col-lg-8 col-md-10">
<span className="badge badge-primary badge-pill">
What we do
</span>
<h3 className="mt-4">Leading digital agency for <span className="text-warning typed" id="type-example-1" data-type-this="business, modern, dedicated"></span> solutions</h3>
</div>
</div>
<div className="row row-grid">
<div className="col-md-4">
<div className="pb-4">
<div className="icon">
<img alt="Image placeholder" src="../../assets/img/svg/icons/Apps.svg" className="svg-inject img-fluid" />
</div>
</div>
<h5>Designed for developers</h5>
<p className="text-muted mb-0">Quick contains components and pages that are built to be customized and used in any combination.</p>
</div>
<div className="col-md-4">
<div className="pb-4">
<div className="icon">
<img alt="Image placeholder" src="../../assets/img/svg/icons/Ballance.svg" className="svg-inject img-fluid" />
</div>
</div>
<h5>Responsive and scalable</h5>
<p className="text-muted mb-0">Scalable and easy to maintain, Quick enables consistency while developing new features and pages.</p>
</div>
<div className="col-md-4">
<div className="pb-4">
<div className="icon">
<img alt="Image placeholder" src="../../assets/img/svg/icons/Book.svg" className="svg-inject img-fluid" />
</div>
</div>
<h5 className="">Very well documented</h5>
<p className="text-muted mb-0">No matter you are a developer or new to web design, you will find our theme very easy to customize with an intuitive code.</p>
</div>
</div>
</div>
</section>
</div>
);
}
export default App;
Now, let's import everything we need from the custom theme in index.js
:
...
import './assets/css/quick-website.css';
import './assets/js/quick-website.js';
import './assets/libs/@fortawesome/fontawesome-free/css/all.min.css';
import './assets/libs/jquery/dist/jquery.min.js';
...
However, when I import the core JS
(quick-website.js) file of the time, I get this types of errors:
- From
quick-website.js
- From 'jquery.min.js`
What am I missing here?
答案1
得分: 1
不要有别的内容,只返回翻译好的部分:
与从资产中导入 jquery.min.js
不同,你应该使用 npm 安装 jquery 包,然后在需要它们的文件中导入相关模块。这是更"React"的做法,从命令行更新依赖项要容易得多。
- 从命令行运行
npm install jquery
- 现在,在需要它们的地方导入模块(在这种情况下,
quick-website.js
):
import $ from 'jquery'
一般来说,如果你看到错误 Something
未定义,请检查是否已导入了该模块。
英文:
Rather than importing jquery.min.js
from assets, you should use npm to install the jquery package and then import relevant modules in the files where you need them. This is a more "react" way of doing things and it's much easier to update dependencies from the command line.
- Run
npm install jquery
from the command line - Now, just import modules where you need them (in this case,
quick-website.js
):
import $ from 'jquery'
In general, if you see the error 'Something' is not defined
, checking if you have imported the module is a good place to start.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论