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がいるよ