console
new Vue({
el: '#app',
data: {
borderRadius: '0%',
isRed: true
},
methods: {
start: function() {
var vm = this;
setInterval(function() {
vm.isRed = !vm.isRed;
},
1000)
},
changeShape: function() {
if (this.borderRadius == '0%') {
this.borderRadius = '50%';
} else {
this.borderRadius = '0%';
}
}
}
})
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">
</script>
<div id="app">
<div class="shape" @click="changeShape()" :style="{'border-radius':borderRadius}">
</div>
<button @click="start">
开始
</button>
<div class="shape" :class="{red:isRed,blue:!isRed}">
</div>
</div>
.shape {
width: 100px;
height: 100px;
margin: 10px;
background-color: orange;
display: inline-block;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}