0
0

More than 3 years have passed since last update.

computed で classを動的に指定

Posted at

html

index.html
<div id="app">
  <p :class="textStyle">test text</p>
</div>

css

style.css
.textColor{
  color: blue;
}

.textFont {
  font-size: 30px;
  background: red;
}
Vue.js
new Vue({
  el: "#app",
  data: function(){
      return {
          shouldApply: true
      }
  },
  computed: {
      textStyle: function() {
          return {
              textColor: this.shouldApply,
              textFont: this.shouldApply
          }
      }
  }
})

※computedはreturnとthisがいるよ

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