Vue
VueJS2: Section 3
by Aubrey Taylor
HTML
<div id="app">
<div class="demo"
:style="style"
></div>
<div class="demo"></div>
<div class="demo"
:style="[style, {height: width + 'px'}]"
></div>
<hr>
<input type="text" v-model="color">
<input type="text" v-model="width">
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica, sans-serif;
}
.demo {
width: 100px;
height: 100px;
background: gray;
display: inline-block;
margin: 10px;
cursor: pointer;
}
.red {
background: red;
}
.green {
background: green;
}
.blue {
background: blue;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
Vue
new Vue({
el: "#app",
data: {
color: "green",
width: 100,
},
computed: {
style: function() {
return {
backgroundColor: this.color,
width: this.width + "px",
}
}
}
})