简体   繁体   English

为什么 bulma 会覆盖我的 vue3 组件 css?

[英]Why is bulma overriding my vue3 component css?

I'm using bulma with a vue cli 3 project, and I've included the bulma import as follows under index.js我正在将 bulma 与 vue cli 3 项目一起使用,并且我在index.js下包含了 bulma 导入,如下所示

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
require('@/assets/main.scss');<< This contains a single line @import '~bulma';

Then I have css specified in the style tag of my individual components.然后我在各个组件的style标签中指定了 css。 When I load the page, I can see the bulma's css is the last one on the list of style tags, as follows加载页面时,可以看到bulma的css是style标签列表的最后一个,如下

<style type="text/css">
.componentSpecificClass{
    color:white;
}
</style>

<style type="text/css">/*! bulma.io v0.9.2 | MIT License | github.com/jgthms/bulma */
/* Bulma Utilities */
.button, .input, .textarea, .select select, .file-cta,
...
</style>

This means that all my css can be overriden by bulma's if their classes are more specific.这意味着我所有的 css 都可以被 bulma 覆盖,如果它们的类更具体的话。 Ideally I'd want my components' css to take precedence and I would normally do that by placing bulma's css higher in the list of style tags.理想情况下,我希望我的组件的 css 优先,我通常会通过在style标签列表中将 bulma 的 css 放在更高的位置来做到这一点。

Since the style tags are being injected by webpack's build process, I don't know how to influence this.由于style标签是由 webpack 的构建过程注入的,我不知道如何影响这一点。

Is this the default behaviour and if so, how can I override bulma's css without making my rules more specific (with ids for example) or without having to explicitly override the bulma css with sass.这是默认行为吗?如果是这样,我怎样才能覆盖bulma的css而不使我的规则更具体(例如使用id)或不必用Z1F8DC276F8040001419C64E9显式覆盖bulma css。

I was able to resolve this by moving the bulma import to the top of main.js and also changing it from require to import , as follows我能够通过将main.js import 移动到 main.js 的顶部并将其从require更改为import来解决这个问题,如下所示

Before

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
require('@/assets/main.scss');<< This contains a single line @import '~bulma';

Now现在

import '@/assets/main.scss';
import '@fortawesome/fontawesome-free/css/all.css'
import '@fortawesome/fontawesome-free/js/all.js'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

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

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