实现如图所示的菜单效果

<style>
    body{
        width: 600px;
    }
    a{
        text-decoration: none; /* 去掉下划线 */
        display: block;
        color: #fff; /* 字体颜色 */
        width: 120px;
        height: 40px;
        line-height: 40px;
        border: 1px solid #fff;
        border-width: 1px 1px 0 0;
        background: #255f9e;
    }
    li{
        list-style-type: none;
    }
    #app > li{
        float: left;
        text-align: center;
        position: relative;
    }
    #app li a:hover{
        color: #fff;
        background: #ffb100;
    }
    #app li ul{
        position: absolute;
        left: -40px;
        top: 40px;
        margin-top: 1px;
        font-size: 12px;
    }
</style>
<body>
    <div id="app">
        <li v-for="menu in menus" @mouseover="menu.show = !menu.show" @mouseout="menu.show = !menu.show">
            <a :href="menu.url">{{ menu.name }}</a>
            <ul v-show="menu.show">
                <li v-for="sub in menu.subMenus">
                    <a :href="sub.url">{{ sub.name }}</a>
                </li>
            </ul>
        </li>
    </div>
    <script>
        const vm = new Vue({
            el:'#app',
            data: {
                menus: [
                    {
                        name:'我的淘宝', //主菜单的名称
                        url: '#', //主菜单对应的地址
                        show: false, //是否显示子菜单
                        subMenus: [ //子菜单的列表
                            {
                                name: '已买到的宝贝',
                                url: '#'
                            },
                            {
                                name: '已卖出的宝贝',
                                url: '#'
                            }
                        ]
                    },
                    {
                        name: '收藏夹',
                        url: '#',
                        show: false,
                        subMenus:[
                            {
                                name: '收藏的宝贝',
                                url: '#'
                            },
                            {
                                name: '收藏的店铺',
                                url: '#'
                            }
                        ]
                    }
                ]
            }
        })
    </script>

音乐播放器

<style>
    .active{
        background: red;
    }
</style>
<body>
    <div id="app">
        <audio :src="songs[currentIndex].songUrl" controls autoplay></audio>
        <ul>
            <li v-for="song in songs" @click="play(song.id)" :class="{active: song.id === currentIndex+1}">
                <h2>歌名:{{ song.name }}</h2>
                <p>歌手:{{ song.artist }}</p>
            </li>
        </ul>
    </div>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                songs:[
                    {
                        id: 1,
                        name: '别知己', //音乐名
                        songUrl: './audio/别知己.mp3', //音乐地址
                        artist:'潇斌' //歌手
                    },
                    {
                        id: 2,
                        name: '西海情歌',
                        songUrl: './audio/西海情歌.mp3',
                        artist:'刀郎'
                    },
                    {
                        id:3,
                        name: '粉丝记事本',
                        songUrl: './audio/粉丝记事本.mp3',
                        artist: '徐誉滕'
                    }
                ],
                currentIndex: 0  //当前用户选择的音乐的下标
            },
            methods: {
                play(id){
                    this.currentIndex = id - 1
                }
            }
        })
    </script>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值