【问题标题】:Buefy not reacting to Sass stylingBuefy 对 Sass 样式没有反应
【发布时间】:2021-09-28 07:04:42
【问题描述】:

这里是初学者...我有一个简单的 Vue (2) 应用程序并安装了 node-sass 和 sass-loader。按照说明here

Buefy 在 main.js 中导入,这里是(我的下半部分)App.vue:

<style lang="scss">
// Import Bulma's core
@import "~bulma/sass/utilities/_all";

// Set your colors
$primary: #8c67ef;
$primary-light: findLightColor($primary);
$primary-dark: findDarkColor($primary);
$primary-invert: findColorInvert($primary);
$twitter: #4099FF;
$twitter-invert: findColorInvert($twitter);

// Lists and maps
$custom-colors: null !default;
$custom-shades: null !default;

// Setup $colors to use as bulma classes (e.g. 'is-twitter')
$colors: mergeColorMaps(
    (
        "white": (
            $white,
            $black,
        ),
        "black": (
            $black,
            $white,
        ),
        "light": (
            $light,
            $light-invert,
        ),
        "dark": (
            $dark,
            $dark-invert,
        ),
        "primary": (
            $primary,
            $primary-invert,
            $primary-light,
            $primary-dark,
        ),
        "link": (
            $link,
            $link-invert,
            $link-light,
            $link-dark,
        ),
        "info": (
            $info,
            $info-invert,
            $info-light,
            $info-dark,
        ),
        "success": (
            $success,
            $success-invert,
            $success-light,
            $success-dark,
        ),
        "warning": (
            $warning,
            $warning-invert,
            $warning-light,
            $warning-dark,
        ),
        "danger": (
            $danger,
            $danger-invert,
            $danger-light,
            $danger-dark,
        ),
    ),
    $custom-colors
);

// Links
$link: $primary;
$link-invert: $primary-invert;
$link-focus-border: $primary;

// Import Bulma and Buefy styles
@import "~bulma";
@import "~buefy/src/scss/buefy";

</style>

所以我运行 npm run serve - 我的应用程序运行良好 - 但只有默认的 Bulma 样式。那就是 - 如果我添加:

<style lang="css">
.somestyle {
 color: red;
}
</style>

...然后点击“保存” - 应用以正确的样式加载。但是如果我在浏览器中点击刷新 - 自定义样式就会消失,我会回到原来的 Bulma 样式。基本上,我无法让自定义 scss “粘贴”。

我已经在另一个应用程序中使用(据我所见)完全相同的设置!这个问题让我很头疼:-/

"vue": "^2.6.12",
"buefy": "^0.9.4",
"bulma": "^0.9.3",
"node-sass": "^5.0.0",
"sass-loader": "^10.1.0"  

不知道这里还包括什么 - 但任何想法都将不胜感激!

【问题讨论】:

    标签: vue.js sass vuejs2 bulma buefy


    【解决方案1】:

    我认为问题可能实际上是您没有全局连接变量。

    https://vue-loader.vuejs.org/guide/pre-processors.html#sharing-global-variables

    这是我将Bulma 连接到我的Vue 项目的方法,我认为您可以在连接Buefy 时使用相同的模式:

    // main.ts
    import '@/assets/scss/main.scss'
    
    // main.scss file
    @import "~bulma";
    @import "./_variables.scss"; 
    
    // _variables.scss file
    ...all my sass-variables...
    
    @import "~bulma/sass/utilities/_all";
    
    // vue.config.js
    module.exports = {
      css: {
        loaderOptions: {
          scss: {
            prependData: '@import "~@/assets/scss/_variables.scss";'
          }
        }
      }
    }
    

    【讨论】:

    • 感谢您的意见,@Eduardo。这个解决方案也只是加载 bulma 的主要设置,我的变量(在 _variables.scss 中)被忽略了。
    • ...但是如果我在 mains.scss 中的导入上方添加我的变量 - 一切正常!
    • 是的 - 非常感谢@Eduardo。它确实有帮助:-)
    猜你喜欢
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2021-12-21
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    相关资源
    最近更新 更多