1. 程式人生 > 其它 >2021-7-7 VUE筆記2

2021-7-7 VUE筆記2

Vue的動態樣式例項1

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
  .active{
    border: 2px solid darkred;
    width: 100px;
    height: 100px;
  }
</style>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<
body> <div id="app"> <input type="button" value="aaa" @click="handle" name=""> <div :class="{active:vis}"></div> </div> <script> Vue.config.keyCodes.a=65; new Vue({ el: '#app', data: { vis:false }, methods:{ handle:function(event){ this
.vis=this.vis?false:true; // this.vis=!this.vis; } } }) </script> </body> </html>
View Code

Vue的動態樣式例項2

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
  .active{
    border: 2px solid darkred;
    width: 100px;
    height
: 100px; } .new{ background-color: green; } </style> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <input type="button" value="aaa" @click="handle" name=""> <div :class="[activeClass,newClass]"></div> </div> <script> Vue.config.keyCodes.a=65; new Vue({ el: '#app', data: { activeClass:'active', newClass:'new' }, methods:{ handle:function(event){ this.newClass=''; } } }) </script> </body> </html>
View Code