LoginSignup
1
0

More than 5 years have passed since last update.

Vue.jsでtemplateでclassを複数定義したいならこうしよう

Last updated at Posted at 2019-04-02

結論

Vue.jsでこんな感じでかけます

<template lang="pug">
.hoge-container
  .box-wrapper(:class="[propsClass, { active: isActive }]")
</template>

<script>
export default {
  name: 'hoge-container'
  props: {
    propsClass: {
      type: String,
      required: false,
    },
    isActive: {
      type: Boolean,
      required: true,
    }
  }
}
</script>

説明

この書き方の場合、 propsClass には class名が String で渡ってきたら、そのまま classに入る。そして、 isActivetrue で渡ってきたら、 active クラスが付与される。

補足:これでもok

<template lang="pug">
.hoge-container
  .box-wrapper(:class="[propsClassA, propsClassB, propsClassC]")
</template>
<template lang="pug">
.hoge-container
  .box-wrapper(:class="{active: isActive, big: isBig}")
</template>
1
0
1

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