解決Vue項(xiàng)目側(cè)邊欄icon圖換成自己的圖標(biāo)之后要兩個(gè)圖片進(jìn)行交替的問(wèn)題

<template>
    <div class="left-menu-box">
        <el-card>
            <!-- <el-button style="font-size: 16px; color: white;" v-model="isCollapse" @click="isCollapse=!isCollapse" class="menu-setting icon-toggle"
          type="text" icon="el-icon-s-fold"></el-button> -->
            <el-menu router class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse" v-for="item in tableData"
             :key="item.index">
                <el-menu-item :index="item.page" @click="handleChange(item)">
                    <img :src="item.img" alt="">
                    <span slot="title">{{item.name}}</span>
                </el-menu-item>
            </el-menu>
        </el-card>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                isCollapse: false,
                tableData: [{
                    index: '1',
                    name: "課程表",
                    page: "/curriculum/list",
                    img: require('../assets/images/leftmenu/kechenbiao.png')
                }, {
                    index: '2',
                    name: "學(xué)習(xí)報(bào)告",
                    page: "/study/report",
                    img: require('../assets/images/leftmenu/xuexibaogao.png')
                }, {
                    index: '3',
                    name: "課程文件",
                    page: "/document/list",
                    img: require('../assets/images/leftmenu/kechenwenjian.png')
                }, {
                    index: '4',
                    name: "錯(cuò)題庫(kù)",
                    page: "/question/list",
                    img: require('../assets/images/leftmenu/cuotiku.png')
                }, ]
            };
        },
        methods: {
            //點(diǎn)擊事件
            handleChange(item) {
                this.handleClear();
                var oLi = document.querySelectorAll('.left-menu-box ul li');
                if (item.index == 1) {
                    this.tableData[0].img = require('../assets/images/leftmenu/kechengbiao1.png')
                    oLi[0].classList.add("is-active")
                }
                if (item.index == 2) {

                    this.tableData[1].img = require('../assets/images/leftmenu/xuexibaogao1.png')
                    oLi[1].classList.add("is-active")
                }
                if (item.index == 3) {
                    this.tableData[2].img = require('../assets/images/leftmenu/kechenwenjian1.png')
                    oLi[2].classList.add("is-active")
                }
                if (item.index == 4) {

                    this.tableData[3].img = require('../assets/images/leftmenu/cuotiku1.png')
                    oLi[3].classList.add("is-active")
                }
            },
            // 清除點(diǎn)擊事件
            handleClear() {
                this.tableData = [{
                    index: '1',
                    name: "課程表",
                    page: "/curriculum/list",
                    img: require('../assets/images/leftmenu/kechenbiao.png')
                }, {
                    index: '2',
                    name: "學(xué)習(xí)報(bào)告",
                    page: "/study/report",
                    img: require('../assets/images/leftmenu/xuexibaogao.png')
                }, {
                    index: '3',
                    name: "課程文件",
                    page: "/document/list",
                    img: require('../assets/images/leftmenu/kechenwenjian.png')
                }, {
                    index: '4',
                    name: "錯(cuò)題庫(kù)",
                    page: "/question/list",
                    img: require('../assets/images/leftmenu/cuotiku.png')
                }, ]
                var oLi = document.querySelectorAll('.left-menu-box ul li');
                for (var k = 0, length = oLi.length; k < length; k++) {
                    oLi[k].classList.remove('is-active')
                }

            },
            handleOpen(key, keyPath) {
                // console.log(key, keyPath);
            },
            handleClose(key, keyPath) {
                // console.log(key, keyPath);
            },
        },
    };
</script>

<style lang="scss">
    .left-menu-box {
        width: 200px;
        position: fixed;
        left: 10px;
        top: 77px;
        overflow: hidden;
        -webkit-transition: width 0.3s;
        transition: width 0.3s;
        z-index: 999;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    }

    .el-menu-vertical-demo {
        width: 164px;
    }

    .el-menu {
        border-right: 0 !important;
    }

    .left-menu {
        border-right: 0;
    }

    .el-menu-item:focus,
    .el-menu-item:hover {
        background-color: whitesmoke !important;
        border-radius: 40px !important;
    }

    .el-menu-item.is-active {
        border-radius: 40px !important;
        background: #018EED !important;
        color: white !important;
    }

    .el-menu-item {
        -webkit-transition: border-color 0s, background-color 0s, color 0s !important;
        transition: border-color 0s, background-color 0s, color 0s;
        margin: 10px 0 !important;

        span {
            vertical-align: middle;
            // font-size: 16px;
            margin-left: 18px;
        }

        img {
            vertical-align: middle;
            width: 19px;
            height: 18px;
            margin-left: 12px;
        }
    }

    .menu-setting {
        position: absolute;
        top: 10px;
        left: 200px;
    }
</style>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末抓督,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,204評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件揭北,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)鹰溜,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)丁恭,“玉大人曹动,你說(shuō)我怎么就攤上這事∩溃” “怎么了墓陈?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,548評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)第献。 經(jīng)常有香客問(wèn)我贡必,道長(zhǎng),這世上最難降的妖魔是什么庸毫? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,657評(píng)論 1 293
  • 正文 為了忘掉前任仔拟,我火速辦了婚禮,結(jié)果婚禮上飒赃,老公的妹妹穿的比我還像新娘利花。我一直安慰自己科侈,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,689評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布炒事。 她就那樣靜靜地躺著臀栈,像睡著了一般。 火紅的嫁衣襯著肌膚如雪挠乳。 梳的紋絲不亂的頭發(fā)上权薯,一...
    開(kāi)封第一講書(shū)人閱讀 51,554評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音欲侮,去河邊找鬼崭闲。 笑死,一個(gè)胖子當(dāng)著我的面吹牛威蕉,可吹牛的內(nèi)容都是我干的刁俭。 我是一名探鬼主播,決...
    沈念sama閱讀 40,302評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼韧涨,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼牍戚!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起虑粥,我...
    開(kāi)封第一講書(shū)人閱讀 39,216評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤如孝,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后娩贷,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體第晰,經(jīng)...
    沈念sama閱讀 45,661評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,851評(píng)論 3 336
  • 正文 我和宋清朗相戀三年彬祖,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了茁瘦。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,977評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡储笑,死狀恐怖甜熔,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情突倍,我是刑警寧澤腔稀,帶...
    沈念sama閱讀 35,697評(píng)論 5 347
  • 正文 年R本政府宣布,位于F島的核電站羽历,受9級(jí)特大地震影響焊虏,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜秕磷,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,306評(píng)論 3 330
  • 文/蒙蒙 一诵闭、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧跳夭,春花似錦涂圆、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,898評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至颈抚,卻和暖如春踩衩,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背贩汉。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,019評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工驱富, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人匹舞。 一個(gè)月前我還...
    沈念sama閱讀 48,138評(píng)論 3 370
  • 正文 我出身青樓褐鸥,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親赐稽。 傳聞我的和親對(duì)象是個(gè)殘疾皇子叫榕,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,927評(píng)論 2 355