React – 集成自定义的Bootstrap主题

huangapple go评论49阅读模式
英文:

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)时,我遇到了这些类型的错误:

  1. 来自quick-website.js

React – 集成自定义的Bootstrap主题

  1. 来自jquery.min.js

React – 集成自定义的Bootstrap主题

我在这里漏掉了什么?

英文:

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.

React – 集成自定义的Bootstrap主题

Now, let's customize the App.js component in React with some custom code:

function App() {
return (
&lt;div className=&quot;App&quot;&gt;
&lt;section className=&quot;slice slice-lg delimiter-top delimiter-bottom&quot;&gt;
&lt;div className=&quot;container&quot;&gt;
&lt;div className=&quot;row mb-6 justify-content-center text-center&quot;&gt;
&lt;div className=&quot;col-lg-8 col-md-10&quot;&gt;
&lt;span className=&quot;badge badge-primary badge-pill&quot;&gt;
What we do
&lt;/span&gt;
&lt;h3 className=&quot;mt-4&quot;&gt;Leading digital agency for &lt;span className=&quot;text-warning typed&quot; id=&quot;type-example-1&quot; data-type-this=&quot;business, modern, dedicated&quot;&gt;&lt;/span&gt; solutions&lt;/h3&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div className=&quot;row row-grid&quot;&gt;
&lt;div className=&quot;col-md-4&quot;&gt;
&lt;div className=&quot;pb-4&quot;&gt;
&lt;div className=&quot;icon&quot;&gt;
&lt;img alt=&quot;Image placeholder&quot; src=&quot;../../assets/img/svg/icons/Apps.svg&quot; className=&quot;svg-inject img-fluid&quot; /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h5&gt;Designed for developers&lt;/h5&gt;
&lt;p className=&quot;text-muted mb-0&quot;&gt;Quick contains components and pages that are built to be customized and used in any combination.&lt;/p&gt;
&lt;/div&gt;
&lt;div className=&quot;col-md-4&quot;&gt;
&lt;div className=&quot;pb-4&quot;&gt;
&lt;div className=&quot;icon&quot;&gt;
&lt;img alt=&quot;Image placeholder&quot; src=&quot;../../assets/img/svg/icons/Ballance.svg&quot; className=&quot;svg-inject img-fluid&quot; /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h5&gt;Responsive and scalable&lt;/h5&gt;
&lt;p className=&quot;text-muted mb-0&quot;&gt;Scalable and easy to maintain, Quick enables consistency while developing new features and pages.&lt;/p&gt;
&lt;/div&gt;
&lt;div className=&quot;col-md-4&quot;&gt;
&lt;div className=&quot;pb-4&quot;&gt;
&lt;div className=&quot;icon&quot;&gt;
&lt;img alt=&quot;Image placeholder&quot; src=&quot;../../assets/img/svg/icons/Book.svg&quot; className=&quot;svg-inject img-fluid&quot; /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h5 className=&quot;&quot;&gt;Very well documented&lt;/h5&gt;
&lt;p className=&quot;text-muted mb-0&quot;&gt;No matter you are a developer or new to web design, you will find our theme very easy to customize with an intuitive code.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;/div&gt;
);
}
export default App;

Now, let's import everything we need from the custom theme in index.js:

...
import &#39;./assets/css/quick-website.css&#39;;
import &#39;./assets/js/quick-website.js&#39;;
import &#39;./assets/libs/@fortawesome/fontawesome-free/css/all.min.css&#39;;
import &#39;./assets/libs/jquery/dist/jquery.min.js&#39;;
...

However, when I import the core JS (quick-website.js) file of the time, I get this types of errors:

  1. From quick-website.js

React – 集成自定义的Bootstrap主题

  1. From 'jquery.min.js`

React – 集成自定义的Bootstrap主题

What am I missing here?

答案1

得分: 1

不要有别的内容,只返回翻译好的部分:

与从资产中导入 jquery.min.js 不同,你应该使用 npm 安装 jquery 包,然后在需要它们的文件中导入相关模块。这是更"React"的做法,从命令行更新依赖项要容易得多。

  1. 从命令行运行 npm install jquery
  2. 现在,在需要它们的地方导入模块(在这种情况下,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.

  1. Run npm install jquery from the command line
  2. Now, just import modules where you need them (in this case, quick-website.js):
import $ from &#39;jquery&#39;

In general, if you see the error &#39;Something&#39; is not defined, checking if you have imported the module is a good place to start.

huangapple
  • 本文由 发表于 2023年6月1日 22:26:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76382956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定