Vue簡單PC導航滑鼠懸浮展示子選單
阿新 • • 發佈:2020-12-10
技術標籤:PC端
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.css"
/>
<!-- 引入 Vue 和 Vant 的 JS 檔案 -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/vant.min.js"></script>
<script src="https://sucai.suoluomei.cn/sucai_zs/file/20201202101625-typescript.js" ></script>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
</head>
<style>
* {
margin: 0px;
padding: 0px;
}
.label {
display: flex;
flex-direction : row;
}
.mouse {
display: flex;
flex-direction: column;
align-items: center;
border-right: 1px solid #fff;
}
.sort:last-child {
border-right: unset;
}
.title {
padding: 10px;
box-sizing: border-box;
background-color: red;
color: #fff;
}
.title:hover {
color: #fff;
background-color: blue;
}
.hoverShow {
display: flex;
flex-direction: column;
}
.hoverShow div {
padding: 10px;
box-sizing: border-box;
background-color: #aaa;
color: #fff;
}
.hoverShow div:hover {
background-color: #000;
color: #ffff;
}
</style>
<body>
<div id="Vue">
<div class="label">
<div
v-for="(item,index) in list"
:key="index"
v-on:mouseover="showToggle(index)"
v-on:mouseout="handleHide"
:class="['sort','mouse']"
>
<div class="title">{{item.title}}</div>
<block v-show="index === isShow">
<div v-for="(item1,idx) in item.list" :key="idx" class="hoverShow">
<div v-on:click="handleHide" @click="dianji(item1)">
{{item1}}
</div>
</div>
</block>
</div>
</div>
</div>
</body>
<script>
new Vue({
el: "#Vue",
data: {
list: [
{
title: "導航選單1",
list: ["1", "2", "3"],
},
{
title: "導航選單2",
list: ["2", "2", "3"],
},
{
title: "導航選單3",
list: ["3", "2", "3"],
},
{
title: "導航選單4",
list: ["4", "2", "3"],
},
],
isShow: -1,
},
methods: {
showToggle(index) {
this.isShow = index;
},
handleHide() {
this.isShow = !this.isShow;
},
dianji(e) {
console.log(e);
},
},
created() {
},
});
</script>
</html>