国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Vue2.0點擊切換類名改變樣式的方法

2024-05-06 15:31:17
字體:
來源:轉載
供稿:網友

1、使用index

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>vue導航</title> <style media="screen"> *{ margin:0; padding: 0; } ul li{ list-style: none; } .navul{ margin:100px auto 20px; overflow: hidden; } .navul li{ background-color: #5597b4; padding:18px 30px; float:left; color: #fff; font-size: 18px; cursor: pointer; } .active{ background-color: #5597b4; } .home .home,.new .new,.contact .contact,.service .service{ background-color: skyblue; } .checked{  background: #eff4f7; } </style></head><body> <div id="nav">  <ul>   <li v-for="(relation,index) in relations" v-bind:id="relation.id" v-bind:id="relation.id" v-bind:class="{checked:index==nowIndex}" v-on:click="relationClick(index)">    <i></i>    <span class="">{{relation.text}}</span>   </li>  </ul> </div>  <script src="js/vue.js" charset="utf-8"></script> <script type="text/javascript"> var nav = new Vue({  el:'#nav',  data:{  relations: [   {text:'項目',id:'program'},   {text:'人員',id:'person'},   {text:'機構',id:'organization'},   {text:'技術',id:'tech'},   {text:'地區',id:'location'},   {text:'國家',id:'country'}  ],  nowIndex:0  // willShow:false  },  methods:{  relationClick:function(index){      this.nowIndex=index;  }  } }); </script></body></html>

2、通過改變當前值切換類名

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>點擊切換</title> <style> .glyphicon-minus{  color:#08f; } .glyphicon-plus{  color:purple; }  </style> <script src="js/vue.js"></script></head><body>  <div id="box">  <div style="width:100px; height:100px; background: #6bacdf;" v-show="isDisplay"></div>   <div class="form-group">  <button class="btn"    :class="[isShow?'btn-primary':'']"    @mouseover="toggleShow()"    @mouseout="toggleShow()"    v-text="btnStyle"></button>   </div>   <div class="">  <button class="btn"    :class="[isTrue?'glyphicon-minus':'glyphicon-plus']"     @click="toggleBar()">切換類名按鈕</button>   </div> </div>  <script type="text/javascript">    new Vue({  el:'#box',  data:{   isDisplay:false,   isShow: false,   isTrue:true,   btnStyle: 'Default'  },  methods:{   toggleShow: function() {   this.isShow = !this.isShow;   },   toggleBar:function(){   this.isTrue = !this.isTrue;   }  },  watch: {   isShow: function(newVal) {   // console.log(newVal);   newVal ? this.btnStyle = 'Primary' : this.btnStyle = 'Default'   }  },  });   </script></body></html>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 五河县| 泰州市| 黄石市| 奉化市| 余庆县| 绥棱县| 清涧县| 昌乐县| 华安县| 冕宁县| 衡山县| 雷州市| 万年县| 泸西县| 东平县| 寿阳县| 宁波市| 千阳县| 卢氏县| 新沂市| 闵行区| 内丘县| 富民县| 闽侯县| 红桥区| 广东省| 阿城市| 甘孜县| 准格尔旗| 松潘县| 理塘县| 浦城县| 长泰县| 阿鲁科尔沁旗| 奉贤区| 大安市| 德保县| 唐山市| 大田县| 乌拉特后旗| 黔西|