欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vuejs選中當(dāng)前樣式active的實(shí)例

 更新時(shí)間:2018年08月22日 15:48:18   作者:longzhoufeng  
今天小編就為大家分享一篇vuejs選中當(dāng)前樣式active的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧

如下所示:

<template>
 <div>
  <table id="longzhoufeng" class="table table-striped table-bordered" width="100%" style="border: 0 solid #fff;margin-top: 10px;">
   <thead class="thead-bottom-line">
   <tr>
    <th class="sorting-title">名稱1</th>
    <th class="sorting-title">名稱2</th>
    <th class="sorting-title">名稱3</th>
    <th class="sorting-title">名稱4</th>
   </tr>
   </thead>
   <tbody>
   <tr @click="activeHover(index)" class="list-table-hover" v-for="(item,index) in items" >
    <th class="sorting-title">{{item.text}}</th>
    <th class="sorting-title">{{item.text}}</th>
    <th class="sorting-title">{{item.text}}</th>
    <th class="sorting-title">{{item.text}}</th>
   </tr>
   </tbody>
  </table>
 </div>
</template>

vue js代碼

<script>
 export default {
  data:function() {
   return{
    items: [
     { text: '巴士' },
     { text: '快車' },
     { text: '專車' },
     { text: '順風(fēng)車' },
     { text: '出租車' },
     { text: '代駕' }
    ],
   }
  },
  methods:{
   activeHover:function(index){
    var arrLi=[];
    var aLi=$("table tbody tr")
    for(var i=0;i<aLi.length;i++){
     arrLi.push(aLi[i])
    }
    for( var i=0; i<arrLi.length; i++ ){
     if(arrLi[i] !=this){
      $(arrLi[i]).removeClass("active")
     }

     if(!$(arrLi[i]).hasClass("active")){
      $(arrLi[index]).addClass("active")
     }else{
      $(arrLi[i]).removeClass("active")
     }
    }
   },
  }
 }
</script>

CSS代碼

<style scoped>
 .abc{
  background-color: #2aabd2;
 }
 table>thead.thead-bottom-line{
  border-bottom: 1px solid #eeeeef;
  border-top: 1px solid #eeeeef;
  background-color: #fff;
 }
 table>thead>tr>th.sorting-title{
  height: 35px;
  line-height: 35px;
  border: 0px solid #000000;
  font-weight: bold
 }
 table>tbody>tr.list-table-hover{
  height: 30px;
  line-height: 30px;
  background-color: #fff !important;
  border-top: 0px solid #eeeeef;
  border-left: 0px solid #eeeeef;
  border-right: 0px solid #eeeeef;
  border-bottom: 1px solid #eeeeef;
 }
 table>tbody>tr:hover{
  background-color: rgba(130, 219, 201, .5)!important;
 }
 table>tbody>tr.list-table-hover:hover{
  height: 30px;
  line-height: 20px;
  background-color: rgba(130, 219, 201, .5)!important;
  border-top: 0px solid #eeeeef;
  border-left: 0px solid #eeeeef;
  border-right: 0px solid #eeeeef;
  border-bottom: 1px solid #eeeeef;
 }
 table>tbody>tr.list-table-hover.active{
  background-color: rgba(130, 219, 201, .5)!important;
 }
 table>tbody>tr>td.sorting_content{
  height: 30px;
  line-height: 20px;
  /*background-color: #fff;*/
  border-top: 0px solid #eeeeef;
  border-left: 0px solid #eeeeef;
  border-right: 0px solid #eeeeef;
  border-bottom: 1px solid #eeeeef;
 }
 table>tbody>tr>td.sorting_content:last-child{
  height: 30px;
  line-height: 30px;
  min-width: 120px;
  border-top: 0px solid #eeeeef;
  border-left: 0px solid #eeeeef;
  border-right: 0px solid #eeeeef;
  border-bottom: 1px solid #eeeeef;
 }
</style>

知識(shí)拓展:vue實(shí)現(xiàn)點(diǎn)擊選中,其他的不選中方法

如下所示:

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <meta name="viewport"
   content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>選中效果</title>
 <script src="../static/js/vue.min.js"></script>
 <style>
  ul li.active{
   color: green;
  }
 </style>

</head>
<body>

<div id="app">
 <ul>
  <li v-for="items in navList" :class="{active:items.isActive}" @click="activeFun(items)">
   <a>
    {{items.text}}
   </a>
  </li>
 </ul>
</div>

<script>
 new Vue({
  el: '#app',
  data: {
   navList: [
    {text: '首頁(yè)', isActive: true},
    {text: '簡(jiǎn)介', isActive: false},
    {text: '活動(dòng)', isActive: false},
    {text: '聯(lián)系', isActive: false}
   ]
  },
  methods: {
   activeFun: function(data){
    this.navList.forEach(function(obj){
     obj.isActive = false;
    });
    data.isActive = !data.isActive;
   }
  }
 });
</script>


</body>
</html>

以上這篇vuejs選中當(dāng)前樣式active的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue車牌輸入組件使用方法詳解

    vue車牌輸入組件使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了vue車牌輸入組件的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • Vue項(xiàng)目報(bào)錯(cuò):parseComponent問題及解決

    Vue項(xiàng)目報(bào)錯(cuò):parseComponent問題及解決

    這篇文章主要介紹了Vue項(xiàng)目報(bào)錯(cuò):parseComponent問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Vue頁(yè)面反復(fù)刷新的常見問題及解決方案

    Vue頁(yè)面反復(fù)刷新的常見問題及解決方案

    Vue.js 是一個(gè)流行的前端框架,旨在通過其響應(yīng)式的數(shù)據(jù)綁定和組件化的開發(fā)模式簡(jiǎn)化開發(fā),然而,在開發(fā) Vue.js 應(yīng)用時(shí),頁(yè)面反復(fù)刷新的問題可能會(huì)對(duì)用戶體驗(yàn)和開發(fā)效率產(chǎn)生負(fù)面影響,本文將深入探討 Vue 頁(yè)面反復(fù)刷新的常見原因,并提供詳細(xì)的解決方案
    2024-09-09
  • vue路由--網(wǎng)站導(dǎo)航功能詳解

    vue路由--網(wǎng)站導(dǎo)航功能詳解

    這篇文章主要介紹了vue路由--網(wǎng)站導(dǎo)航功能詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • vue將秒數(shù)轉(zhuǎn)成"時(shí)分秒"格式實(shí)例代碼

    vue將秒數(shù)轉(zhuǎn)成"時(shí)分秒"格式實(shí)例代碼

    在項(xiàng)目中,請(qǐng)求后臺(tái)接口返回的值是秒,這篇文章主要給大家介紹了關(guān)于vue將秒數(shù)轉(zhuǎn)成"時(shí)分秒"格式的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • vue中如何動(dòng)態(tài)設(shè)置css樣式的hover

    vue中如何動(dòng)態(tài)設(shè)置css樣式的hover

    這篇文章主要介紹了vue中如何動(dòng)態(tài)設(shè)置css樣式的hover,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue路由實(shí)現(xiàn)登錄攔截

    vue路由實(shí)現(xiàn)登錄攔截

    這篇文章主要介紹了vue路由如何實(shí)現(xiàn)登錄攔截,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下
    2021-03-03
  • 代理模式在vue中的使用示例解析

    代理模式在vue中的使用示例解析

    這篇文章主要為大家介紹了代理模式在vue中的使用示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • MVVM模型在Vue中的使用詳解

    MVVM模型在Vue中的使用詳解

    MVVM模型主要是為了分離視圖(View)和模型(Model),其優(yōu)點(diǎn)為:低耦合、可重用性、獨(dú)立開發(fā)以及可測(cè)試,視圖和模型分離的特點(diǎn)給了 Vue 很大的啟發(fā),這篇文章主要介紹了MVVM模型在Vue中的使用,需要的朋友可以參考下
    2022-11-11
  • Vue3+elementui plus創(chuàng)建項(xiàng)目的方法

    Vue3+elementui plus創(chuàng)建項(xiàng)目的方法

    這篇文章主要介紹了Vue3+elementui plus創(chuàng)建項(xiàng)目的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12

最新評(píng)論