1. 程式人生 > 其它 >使用ul標籤製作簡單的選單(vue模板)

使用ul標籤製作簡單的選單(vue模板)

先看一下效果圖:

簡單粗暴,上程式碼:

<template>
    <div class="listMenu-wrap">
        <ul class="list-ul" v-for="(item, index) in data" :key="index">
            <li :class="[currentIndex === index ? 'active' : '']" @click="handleClick(index, item)">{{item}}</li>
        </ul>
    </div>
</template>

<script>
    export 
default { name: "ListMenu", data() { return { currentIndex: 0, data:[ "專案列表1", "專案列表2", "專案列表3", "專案列表4" ] } }, methods: { handleClick(index, item) {
this.currentIndex = index } } } </script> <style scoped lang="scss"> .listMenu-wrap{ .list-ul { list-style: none; margin: 0; padding: 0; li{ line-height: 30px; font-size: 16px; padding: 3px 15px;
&:hover{ cursor: pointer; background-color: rgba(69, 86, 118, 0.44); color: #ffffff; } } } .active{ color: #409EFF; } } </style>

原文連結:https://www.cnblogs.com/yiliangmi/p/15241571.html