开始绑定样式的学习

mac_study
roger 2 years ago
parent 443eb58261
commit 812a51eede
  1. 20
      10_绑定样式/绑定样式.html

@ -22,10 +22,11 @@
background-color: blueviolet; background-color: blueviolet;
} }
.test2 { .test2 {
background-color: chartreuse; border-color: brown;
border-width: medium;
} }
.test3 { .test3 {
background-color: brown; border-radius: 20px;
} }
</style> </style>
<script type="text/javascript" src="../vue.js"></script> <script type="text/javascript" src="../vue.js"></script>
@ -34,14 +35,25 @@
</body> </body>
<div id="root"> <div id="root">
<div class="basic">{{name}}</div> <div class="basic" :class="style" @click="changeStyle">{{name}}</div>
<div class="basic" :class="classArr" @click="changeStyle">{{name}}</div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
Vue.config.productionTip = false Vue.config.productionTip = false
new Vue({ new Vue({
el: "#root", el: "#root",
data:{ data:{
name: '测试', name: '测试',
style: "normal",
classArr: ["test1", "test2", "test3"]
},
methods:{
changeStyle(){
// this.style = "happy"
const arr = ['happy', 'sad', 'normal']
const index = Math.floor(Math.random()*3)
this.style = arr[index]
}
} }
}) })
</script> </script>

Loading…
Cancel
Save