primevue-mirror/doc/tabmenu/BasicDoc.vue

266 lines
7.3 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
2023-08-31 13:23:35 +00:00
<p>TabMenu requires a collection of menuitems as its <i>model</i>.</p>
2023-02-28 08:29:30 +00:00
</DocSectionText>
<div class="card">
2023-08-31 13:23:35 +00:00
<TabMenu v-model:activeIndex="active" :model="items">
<template #item="{ label, item, props }">
<router-link v-if="item.route" v-slot="routerProps" :to="item.route" custom>
<a :href="routerProps.href" v-bind="props.action" @click="($event) => routerProps.navigate($event)" @keydown.enter.space="($event) => routerProps.navigate($event)">
<span v-bind="props.icon" />
<span v-bind="props.label">{{ label }}</span>
</a>
</router-link>
</template>
</TabMenu>
2023-02-28 08:29:30 +00:00
<router-view />
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
2023-08-31 13:23:35 +00:00
active: 0,
2023-02-28 08:29:30 +00:00
items: [
{ label: 'Home', icon: 'pi pi-fw pi-home', route: '/tabmenu/' },
2023-08-31 13:23:35 +00:00
{ label: 'Calendar', icon: 'pi pi-fw pi-calendar', route: '/tabmenu/calendar' },
{ label: 'Edit', icon: 'pi pi-fw pi-pencil', route: '/tabmenu/edit' },
{ label: 'Documentation', icon: 'pi pi-fw pi-file', route: '/tabmenu/documentation' },
{ label: 'Settings', icon: 'pi pi-fw pi-cog', route: '/tabmenu/settings' }
2023-02-28 08:29:30 +00:00
],
code: {
2023-09-22 12:54:14 +00:00
basic: `
<TabMenu v-model:activeIndex="active" :model="items">
2023-08-31 13:23:35 +00:00
<template #item="{ label, item, props }">
<router-link v-if="item.route" v-slot="routerProps" :to="item.route" custom>
<a :href="routerProps.href" v-bind="props.action" @click="($event) => routerProps.navigate($event)" @keydown.enter.space="($event) => routerProps.navigate($event)">
<span v-bind="props.icon" />
<span v-bind="props.label">{{ label }}</span>
</a>
</router-link>
</template>
</TabMenu>
2023-02-28 08:29:30 +00:00
<router-view />`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-02-28 08:29:30 +00:00
<div class="card">
2023-08-31 13:23:35 +00:00
<TabMenu v-model:activeIndex="active" :model="items">
<template #item="{ label, item, props }">
<router-link v-if="item.route" v-slot="routerProps" :to="item.route" custom>
<a :href="routerProps.href" v-bind="props.action" @click="($event) => routerProps.navigate($event)" @keydown.enter.space="($event) => routerProps.navigate($event)">
<span v-bind="props.icon" />
<span v-bind="props.label">{{ label }}</span>
</a>
</router-link>
</template>
</TabMenu>
2023-02-28 08:29:30 +00:00
<router-view />
</div>
</template>
<script>
export default {
data() {
return {
2023-08-31 13:23:35 +00:00
active: 0,
2023-02-28 08:29:30 +00:00
items: [
{
label: 'Home',
icon: 'pi pi-fw pi-home',
2023-08-31 13:23:35 +00:00
route: '/'
2023-02-28 08:29:30 +00:00
},
{
label: 'Calendar',
icon: 'pi pi-fw pi-calendar',
2023-08-31 13:23:35 +00:00
route: '/calendar'
2023-02-28 08:29:30 +00:00
},
{
label: 'Edit',
icon: 'pi pi-fw pi-pencil',
2023-08-31 13:23:35 +00:00
route: '/edit'
2023-02-28 08:29:30 +00:00
},
{
label: 'Documentation',
icon: 'pi pi-fw pi-file',
2023-08-31 13:23:35 +00:00
route: '/documentation'
2023-02-28 08:29:30 +00:00
},
{
label: 'Settings',
icon: 'pi pi-fw pi-cog',
2023-08-31 13:23:35 +00:00
route: '/settings'
2023-02-28 08:29:30 +00:00
}
]
}
2023-08-31 13:23:35 +00:00
},
watch: {
$route() {
this.active = this.items.findIndex((item) => this.$route.path === this.$router.resolve(item.route).path);
}
},
mounted() {
this.active = this.items.findIndex((item) => this.$route.path === this.$router.resolve(item.route).path);
2023-02-28 08:29:30 +00:00
}
}
<\/script>`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2023-02-28 08:29:30 +00:00
<div class="card">
2023-08-31 13:23:35 +00:00
<TabMenu v-model:activeIndex="active" :model="items">
<template #item="{ label, item, props }">
<router-link v-if="item.route" v-slot="routerProps" :to="item.route" custom>
<a :href="routerProps.href" v-bind="props.action" @click="($event) => routerProps.navigate($event)" @keydown.enter.space="($event) => routerProps.navigate($event)">
<span v-bind="props.icon" />
<span v-bind="props.label">{{ label }}</span>
</a>
</router-link>
</template>
</TabMenu>
2023-02-28 08:29:30 +00:00
<router-view />
</div>
</template>
<script setup>
2023-09-18 09:51:07 +00:00
import { ref, onMounted, watch } from "vue";
2023-08-31 13:23:35 +00:00
import { useRouter, useRoute } from "vue-router";
2023-02-28 08:29:30 +00:00
2023-08-31 13:23:35 +00:00
const router = useRouter();
const route = useRoute();
2023-09-12 15:33:17 +00:00
const active = ref(0);
2023-02-28 08:29:30 +00:00
const items = ref([
{
label: 'Home',
icon: 'pi pi-fw pi-home',
2023-08-31 13:23:35 +00:00
route: '/'
2023-02-28 08:29:30 +00:00
},
{
label: 'Calendar',
icon: 'pi pi-fw pi-calendar',
2023-08-31 13:23:35 +00:00
route: '/calendar'
2023-02-28 08:29:30 +00:00
},
{
label: 'Edit',
icon: 'pi pi-fw pi-pencil',
2023-08-31 13:23:35 +00:00
route: '/edit'
2023-02-28 08:29:30 +00:00
},
{
label: 'Documentation',
icon: 'pi pi-fw pi-file',
2023-08-31 13:23:35 +00:00
route: '/documentation'
2023-02-28 08:29:30 +00:00
},
{
label: 'Settings',
icon: 'pi pi-fw pi-cog',
2023-08-31 13:23:35 +00:00
route: '/settings'
2023-02-28 08:29:30 +00:00
}
]);
2023-08-31 13:23:35 +00:00
onMounted(() => {
active.value = items.value.findIndex((item) => route.path === router.resolve(item.route).path);
})
watch(
route,
() => {
active.value = items.value.findIndex((item) => route.path === router.resolve(item.route).path);
},
{ immediate: true }
);
2023-02-28 08:29:30 +00:00
<\/script>`,
pages: [
{
tabName: 'HomeDemo',
content: `
<template>
2023-08-02 14:03:56 +00:00
<div class="p-4">
2023-02-28 08:29:30 +00:00
<h5>Home Component Content</h5>
</div>
</template>
<script>
export default {
}
<\/script>
`
},
{
tabName: 'CalendarDemo',
content: `
<template>
2023-08-02 14:03:56 +00:00
<div class="p-4">
2023-02-28 08:29:30 +00:00
<h5>Calendar Component Content</h5>
</div>
</template>
<script>
export default {
}
<\/script>
`
},
{
tabName: 'EditDemo',
content: `
<template>
2023-08-02 14:03:56 +00:00
<div class="p-4">
2023-02-28 08:29:30 +00:00
<h5>Edit Component Content</h5>
</div>
</template>
<script>
export default {
}
<\/script>
`
},
{
tabName: 'DocumentationDemo',
content: `
<template>
2023-08-02 14:03:56 +00:00
<div class="p-4">
2023-02-28 08:29:30 +00:00
<h5>Documentation Component Content</h5>
</div>
</template>
<script>
export default {
}
<\/script>
`
},
{
tabName: 'SettingsDemo',
content: `
<template>
2023-08-02 14:03:56 +00:00
<div class="p-4">
2023-02-28 08:29:30 +00:00
<h5>Settings Component Content</h5>
</div>
</template>
<script>
export default {
}
<\/script>`
}
]
}
};
2023-08-31 13:23:35 +00:00
},
watch: {
$route() {
this.active = this.items.findIndex((item) => this.$route.path === this.$router.resolve(item.route).path);
}
},
mounted() {
this.active = this.items.findIndex((item) => this.$route.path === this.$router.resolve(item.route).path);
2023-02-28 08:29:30 +00:00
}
};
</script>