layui/example/src/view/component.vue

89 lines
2.1 KiB
Vue
Raw Normal View History

2021-10-22 01:18:40 +00:00
<template>
<lay-layout>
<lay-side>
2021-10-25 17:14:17 +00:00
<lay-scroll style="overflow-y: scroll">
2021-10-24 12:35:43 +00:00
<ul class="layui-menu layui-menu-lg layui-menu-docs">
<li
v-for="menu in menus"
:key="menu"
class="layui-menu-item-group"
lay-options="{type: 'group', isAllowSpread: true}"
>
<div class="layui-menu-body-title">{{ menu.title }}</div>
<hr />
<ul>
<li
v-for="children in menu.children"
:key="children"
:class="[
currentPath === children.path
? 'layui-menu-item-checked2'
: '',
]"
@click="handleClick(children)"
>
<div class="layui-menu-body-title">
<router-link :to="children.path">
<span>{{ children.title }}</span>
<span class="layui-font-12 layui-font-gray">
{{ children.subTitle }}
</span>
</router-link>
</div>
</li>
</ul>
</li>
</ul>
</lay-scroll>
</lay-side>
<lay-body>
2021-12-31 01:00:45 +00:00
<div
style="
padding: 20px;
margin-right: 180px;
transition: margin 240ms 60ms;
"
>
<router-view />
</div>
</lay-body>
</lay-layout>
2021-10-22 01:18:40 +00:00
</template>
<script>
2022-01-04 10:12:13 +00:00
import { ref, watch } from "vue";
import { useRouter, useRoute } from "vue-router";
2022-01-12 06:19:06 +00:00
import menus from "./utils/menus";
2021-10-22 01:18:40 +00:00
export default {
setup() {
2022-01-04 10:12:13 +00:00
const route = useRoute();
const router = useRouter();
const currentPath = ref("/zh-CN/guide");
2021-10-22 01:18:40 +00:00
watch(
() => route.path,
(val) => {
2022-01-04 10:12:13 +00:00
currentPath.value = val;
2021-10-22 01:18:40 +00:00
},
{
immediate: true,
deep: true,
}
2022-01-04 10:12:13 +00:00
);
2021-10-22 01:18:40 +00:00
2022-01-04 10:12:13 +00:00
const selected = ref(1);
2021-10-22 01:18:40 +00:00
const handleClick = function (menu) {
2022-01-04 10:12:13 +00:00
selected.value = menu.id;
router.push(menu.path);
};
2021-10-22 01:18:40 +00:00
return {
menus,
selected,
currentPath,
handleClick,
2022-01-04 10:12:13 +00:00
};
2021-10-22 01:18:40 +00:00
},
2022-01-04 10:12:13 +00:00
};
2021-10-23 07:54:37 +00:00
</script>