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項(xiàng)目報(bào)錯(cuò):parseComponent問題及解決
這篇文章主要介紹了Vue項(xiàng)目報(bào)錯(cuò):parseComponent問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05vue將秒數(shù)轉(zhuǎn)成"時(shí)分秒"格式實(shí)例代碼
在項(xiàng)目中,請(qǐng)求后臺(tái)接口返回的值是秒,這篇文章主要給大家介紹了關(guān)于vue將秒數(shù)轉(zhuǎn)成"時(shí)分秒"格式的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06vue中如何動(dòng)態(tài)設(shè)置css樣式的hover
這篇文章主要介紹了vue中如何動(dòng)態(tài)設(shè)置css樣式的hover,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10Vue3+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