LoginSignup
1
0

More than 1 year has passed since last update.

Nuxt BuefyのグローバルCSS汚染を防ぐ

Last updated at Posted at 2021-08-20

css統合用のmain.scssを作成。
nuxt-buefyのoptionsからcssの適用をfalseにします。

nuxt.config.js
  css: ['~/assets/scss/main.scss'],

  modules: [
    [
      'nuxt-buefy',
      {
        /* buefy options */
        css: false,
      },
    ],
  ],

グローバルcssを何かしらのクラスでラップします。
(今回は.bulmaというクラスを使います。)
.bulma クラス配下にbulma, buefyのcssが展開されるようにimportします。

~/assets/scss/main.scss
// bulma
.bulma {
  @import '~bulma/bulma.sass';
  @import '~buefy/src/scss/buefy.scss';
}

buefyを使用するコンポーネントのrootに.bulmaクラスをつけることで
コンポーネント内部にのみbulma・buefyのcssが適用されます。

temp.vue
<template lang="pug">
  div.bulma
    b-field.grouped
      ~~
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0