作业一
<head>
<style>
.dbb {
height: 200px;
width: 200px;
}
</style>
</head>
<body>
<div id="app">
<div class="dbb" :style="{backgroundColor:color}"></div>
<button @click="b1">变红</button>
<button @click="b2">变黄</button>
<button @click="b3">变蓝</button>
</div>
</body>
<script src="js/vue.js"></script>
<script>
new Vue({
el: '#app',
data: {
color: 'black'
},
methods: {
b1() {
this.color = 'red'
},
b2() {
this.color = 'yellow'
},
b3() {
this.color = 'blue'
}
}
})
</script>
</html>
作业二
<head>
<meta charset="UTF-8">
<title></title>
<style>
.wrap {
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<div id="app">
<div class="wrap" :style="{backgroundColor: color}" @click="changeColor"></div>
</div>
</body>
<script src="js/vue.js"></script>
<script>
new Vue({
el: '#app',
data: {
color: 'black',
count: 0,
colorArr: ['cyan', 'pink', 'green']
},
methods: {
changeColor() {
let n = this.count++;
this.color = this.colorArr[n % this.colorArr.length];
}
}
})
</script>
</html>