Upgrade to Pro — share decks privately, control downloads, hide ads and more …

VueでCSSモジュールを使った感想

 VueでCSSモジュールを使った感想

Yasushi Asahi

May 14, 2019
Tweet

More Decks by Yasushi Asahi

Other Decks in Programming

Transcript

  1. ScopedParent.vue ScopedChild.vue <template> <div class="wrapper"> <h2>スコープドチャイルド</h2> </div> </template> <style scoped>

    .wrapper { background-color: lime; } </style> <template> <div class="wrapper"> <h2>スコープドペアレント</h2> <ScopedChild /> </div> </template> <style scoped> .wrapper { padding: 20px; background-color: lightcyan; } </style> <div data-v-4f362c8a class="wrapper"> <h2 data-v-4f362c8a>スコープドペアレント</h2> <div data-v-0dcdfa6c data-v-4f362c8a class="wrapper"> <h2 data-v-0dcdfa6c>スコープドチャイルド</h2> </div> </div> scopedは 普通に 競合する
  2. ModuleParent.vue ModuleChild.vue <template> <div :class="$style.wrapper"> <h2>モジュールチャイルド</h2> </div> </template> <style module>

    .wrapper { background-color: lime; } </style> <template> <div :class="$style.wrapper"> <h2>モジュールペアレント</h2> <ModuleChild /> </div> </template> <style module> .wrapper { padding: 20px; background-color: lightcyan; } </style> moduleは いくぶん 安心 <div class="ModuleParent_wrapper_1qsYl"> <h2>モジュールペアレント</h2> <div class="ModuleChild_wrapper_1XBnr"> <h2>モジュールチャイルド</h2> </div> </div>
  3. <template> <div :class="$style.wrapper"> <p>親</p> <div :class="$style.container"> <FirstChild :pStyle="$style" /> <SecondChild

    :pStyle="$style" /> </div> </div> </template> <style module> .wrapper { padding: 10px; text-align: center; border: 1px solid indigo; } .container { display: flex; justify-content: space-around; } /* 子供用のスタイル */ .box { padding: 10px; background-color: lightgreen; } .text { text-decoration: underline; } </style> <template> <div :class="pStyle.box"> <h1 :class="pStyle.text">長男</h1> </div> </template> <template> <div :class="pStyle.box"> <h2 :class="pStyle.text">次男</h2> </div> </template> Parent.vue FirstChild.vue SecondChild.vue