简体   繁体   English

如何将 Bootswatch 主题添加到 Vue 项目?

[英]How do I add a Bootswatch theme to a Vue project?

I have Bootstrap working properly in my Vue project.我的 Vue 项目中的 Bootstrap 工作正常。 I would like to use a theme from Bootswatch.我想使用 Bootswatch 的主题。 In my Vue project, I replaced the node_modules/bootstrap/dist/bootstrap.min.css file with one that I downloaded from the Bootswatch site.在我的 Vue 项目中,我用从 Bootswatch 站点下载的文件替换了 node_modules/bootstrap/dist/bootstrap.min.css 文件。 But the new theme didn't change anything.但新主题并没有改变任何东西。 Note: In my main.js I have the following:注意:在我的 main.js 中,我有以下内容:

import 'bootstrap'导入“引导程序”

How do I properly get the new theme to work?如何正确使新主题正常工作?

You should import the css file in main.js as follows 您应该按如下所示将main.js中的css文件导入

import '../node_modules/bootstrap/dist/bootstrap.min.css'

Make sure you have configured your webpack to use css-loader 确保已将Webpack配置为使用css-loader

or 要么

In your root component(mostly App.vue) add two style tags , one for global styles and other for scoped styles if you have any with the scoped attribute.See src imports. 在您的根组件(主要是App.vue)中添加两个样式标签,一个用于全局样式,另一个用于范围样式(如果您具有任何具有scoped属性的属性) 。请参见src导入。

<style src='path/to/node_modules/bootstrap/dist/bootstrap.min.css'>
    /* global styles */
</style> 

<style scoped>
    /* local styles */
</style> 
  • Start by installing some dependencies: 首先安装一些依赖项:
    yarn add bootstrap bootswatch jquery popper.js
  • Then add this lines to your entry point file main.js : 然后将此行添加到您的入口点文件main.js
    import "bootstrap"; import "../node_modules/bootswatch/dist/lux/bootstrap.min.css"; import "jquery"; import "popper.js";

    lux is a theme name, so you can replace it with a theme of your choice. lux是一个主题名称,因此您可以将其替换为您选择的主题。 😎 😎

尝试清除浏览器缓存并重新启动正在运行的任何vue

if you want to use npm...如果你想使用 npm...

npm install bootstrap bootswatch jquery popper.js

Then add this lines to your entry point file main.js:

import "bootstrap";
import "../node_modules/bootswatch/dist/theme/bootstrap.min.css";
import "jquery";
import "popper.js"

replace theme with your theme (journal,lux...)

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

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