<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css样式控制</title>
<style type="text/css">
div>div{
width: 60px;
height: 60px;
border: 2px solid #bbbbbb;
text-align: center;
line-height: 60px;
font-size: 30px;
margin: 10px;
float: left;
}
.selected{
border-color: #000000;
}
.active{
background-color: #bbbbbb;
}
</style>
</head>
<body>
<div id="app">
<div v-bind:class="randomComputed">1</div>
<div v-bind:class="randomComputed">2</div>
<div v-bind:class="randomMethod()">3</div>
<div v-bind:class="randomMethod()">4</div>
</div>
<script src="../js/vue.js"></script>
<script>
function randomBool(){
return Boolean(Math.round(Math.random()));
}
let vm = new Vue({
el:'#app',
data:{
},
computed:{
randomComputed:function () {
return {
selected:randomBool(),
active:randomBool(),
}
}
},
methods:{
randomMethod(){
return {
selected:randomBool(),
active:randomBool(),
}
}
}
});
</script>
</body>
</html>