您好,登錄后才能下訂單哦!
效果圖如下所示:
<template> <div class="asideBox"> <aside> <ul class="asideMenu"> <li v-for="(item,index) in menuList"> <div class="oneMenu" @click="showToggle(item,index)"> <img v-bind:src="item.imgUrl" /> <span>{{item.name}}</span> </div> <ul v-show="item.isSubShow"> <li v-for="subItem in item.subItems"> <div class="oneMenuChild">{{subItem.name}}</div> </li> </ul> </li> </ul> </aside> </div> </template>
export default { data(){ return{ menuList:[ { name:'字符錄入', imgUrl:require('../assets/images/icon-character.png'), isSubShow:false, subItems:[ { name:'字符錄入' }, { name:'白話文錄入' }, { name:'文言文錄入' }, { name:'小寫數字錄入' } ] }, { name:'票據數據錄入', imgUrl:require('../assets/images/icon-bill.png'), isSubShow:false, subItems:[ { name:'票據錄入' }, { name:'翻打傳票' }, ] }, { name:'交易碼錄入', imgUrl:require('../assets/images/icon-transaction.png'), isSubShow:false, subItems:[ { name:'交易碼錄入' }, { name:'交易名稱錄入' }, ] }, { name:'操作碼錄入', imgUrl:require('../assets/images/icon-operation.png'), isSubShow:false, subItems:[ { name:'操作碼錄入' }, { name:'操作名稱錄入' }, ] }, { name:'票據學習', imgUrl:require('../assets/images/icon-billearn.png'), isSubShow:false, subItems:[ ] }, { name:'內部憑證學習', imgUrl:require('../assets/images/icon-voucher.png'), isSubShow:false, subItems:[ ] }, { name:'現金管理學習', imgUrl:require('../assets/images/icon-cash.png'), isSubShow:false, subItems:[ ] }, ] } }, methods:{ // 點擊展開折疊菜單事件 showToggle:function(item,ind){ this.menuList.forEach(i => { // 判斷如果數據中的menuList[i]的show屬性不等于當前數據的isSubShow屬性那么menuList[i]等于false if (i.isSubShow !== this.menuList[ind].isSubShow) { i.isSubShow = false; } }); item.isSubShow = !item.isSubShow; console.log(item.name) }, } }
<style lang="scss" scoped> $menuBackColor:#f1f1f1; $menuListH2:#8fbfef; .asideBox{ height: 100%; width: 300px; aside{ background: $menuBackColor; height: 100%; .asideMenu{ .oneMenu{ height: 50px; line-height: 50px; font-size: 18px; font-weight: normal; color: #ffffff; background: $menuListH2 url("../assets/images/icon-open.png") no-repeat 280px center; border-bottom: 1px solid #669cd9; img{ width: 20px; height: 20px; margin: 15px 16px 15px 20px; vertical-align: top; } } .oneMenuChild{ padding: 0 20px 0 60px; height: 40px; line-height: 40px; background: $menuBackColor; border-bottom: 1px solid #ffffff; color: #454343; font-size: 18px; } } } } </style>
總結
以上所述是小編給大家介紹的Vue實現側邊菜單欄手風琴效果實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。