Vue实现下拉菜单
1、所实现的具体功能效果2、具体功能实现代码<!DOCTYPE html><html><head><meta charset="utf-8"><title>下拉菜单</title><style type="text/css">body {width: 600px;}
·
1、所实现的具体功能效果
2、具体功能实现代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>下拉菜单</title>
<style type="text/css">
body {
width: 600px;
}
ul {
list-style-type: none;
}
#app > ul > li {
float: left;
text-align: center;
position: relative;
}
a {
text-decoration: none;
display: block;
color: #fff;
width: 120px;
height: 40px;
line-height: 40px;
border: 1px solid #fff;
border: 1px 1px 0 0;
background-color: #255f9e;
}
a:hover {
background-color: burlywood;
}
#app > ul > li ul {
position: absolute;
left: -40px;
}
</style>
</head>
<body>
<div id="app">
<ul>
<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="subMenu in menu.subMenus">
<a :href="subMenu.url">{{subMenu.name}}</a>
</li>
</ul>
</li>
</ul>
</div>
<script src="../../plugings/vue.js"></script>
<script>
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>
</body>
</html>
更多推荐
已为社区贡献2条内容
所有评论(0)