0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Nuxt では、全ページ共通で読み込みたい CSS を nuxt.config.tscss に指定できます。

例えば、以下のように設定します。

// nuxt.config.ts
export default defineNuxtConfig({
  css: [
    '~/assets/css/main.css'
  ]
})

ディレクトリ構成は以下のようになります。

assets/
  css/
    main.css

main.css には、アプリ全体で使いたいスタイルを定義します。

/* assets/css/main.css */
body {
  margin: 0;
  font-family: sans-serif;
}

.meo-btn {
  border-radius: 999px;
}

コンポーネント内の <style scoped> はそのコンポーネント限定、nuxt.config.ts の css はアプリ全体に効く、という使い分けです。

このコンポーネントだけに効かせたいなら今の <style scoped> のままでOKです。複数コンポーネントやページで共通化したい共通ボタン・共通コンテナ・色・余白などはassets/css/main.css に逃がすのがNuxtっぽいです。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?