2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vue.js(または Nuxt.js)でCSS in JavaScript

Last updated at Posted at 2019-01-28

導入

(自分の周りでは)たまに聞くCSS in JavaScriptですが、Reactユーザーの方は、styled-componentsを使ってCSS in JavaScriptを行っているのでしょうか?
では、Vue.jsは??

CSS in JavaScript with Vue.js

50833110-30b41180-138b-11e9-9ddd-20af6afc1747.png

egoist/styled-vue: Use dynamic styles in Vue single-file components. :thumbsup:
実際に自分で使ってみました。

<template>
  <div><h1 class="title">hello there!</h1></div>
</template>

<script>
import { css } from 'styled-vue'
import { modularScale } from 'polished'

export default {
  style: css`
    .title {
      font-size: ${modularScale(2)};
      margin: 0;
      color: red;
      text-align: center;
    }
  `
}
</script>

ちゃんとスタイル効いてる!

まとめ

ということでVue.jsでCSS in JavaScriptを実現できました。
といあえず紹介おわり。

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?