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?

More than 3 years have passed since last update.

【Vue.js】オブジェクト構文について

Last updated at Posted at 2020-07-20

Vue.jsについて必要な知識をまとめました。
自身の備忘録として記載します。

オブジェクト構文について

スタイルを指定する場合には「オブジェクト構文」と呼ばれる書き方をします。

v-bind:class="{ クラス名 : 変数 }"

クラス名の後に変数を指定することができます。

v-bind:classにオブジェクトを設定する

クラスの数が増えてくると、v-bind:class内に全て記述するのが難しくなってきます。なのでv-bind:classにはオブジェクトを値として設定することができます。

スタイルとオブジェクト構文

classにv-bindで値を設定する際にオブジェクト構文を使用して多数のクラスを用意することができました。このオブジェクト構文は他の所でも使用できます。その一つが「style」属性です。

v-bind:style=" オブジェクト構文 "

このようにv-bind:styleにオブジェクト構文を使用して値を設定することができます。style属性はスタイル名と値を必要なだけ記述していきます。

v-bind:styleにオブジェクトを指定する

このvi-bind:styleの場合も、v-bind:classと同様にオブジェクトを値に設定することが可能。設定したオブジェクトの中に、スタイル情報をプロパティとして組み込んでおくことができれば値の設定はもっと容易になります。

参考URL

Vue.js & Nuxt.js超入門
https://www.amazon.co.jp/dp/4798056596?tag=maftracking247988-22&linkCode=ure&creative=6339https://www.amazon.co.jp/dp/4798056596?tag=maftracking247988-22&linkCode=ure&creative=6339

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?