primevue-mirror/doc/megamenu/RouterDoc.vue

181 lines
5.6 KiB
Vue
Raw Normal View History

2023-08-30 13:33:42 +00:00
<template>
<DocSectionText v-bind="$attrs">
2023-11-08 18:16:31 +00:00
<p>Items with navigation are defined with templating to be able to use a router link component, an external link or programmatic navigation.</p>
2023-08-30 13:33:42 +00:00
</DocSectionText>
2024-01-30 08:16:35 +00:00
<DocSectionCode :code="code" hideToggleCode hideStackBlitz />
2023-08-30 13:33:42 +00:00
</template>
<script>
export default {
data() {
return {
code: {
2023-09-22 12:54:14 +00:00
basic: `
<MegaMenu :model="items">
2023-11-08 18:16:31 +00:00
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple :href="href" @click="navigate">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-30 13:33:42 +00:00
</a>
</router-link>
2023-11-08 18:16:31 +00:00
<a v-else v-ripple :href="item.url" :target="item.target">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-30 13:33:42 +00:00
</a>
</template>
2023-10-15 09:38:39 +00:00
</MegaMenu>
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-08-30 13:33:42 +00:00
<div class="card">
<MegaMenu :model="items">
2023-11-08 18:16:31 +00:00
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple :href="href" @click="navigate">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-30 13:33:42 +00:00
</a>
</router-link>
2023-11-08 18:16:31 +00:00
<a v-else v-ripple :href="item.url" :target="item.target">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-30 13:33:42 +00:00
</a>
</template>
</MegaMenu>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
2023-11-08 18:16:31 +00:00
label: 'Navigation',
icon: 'pi pi-link',
2023-08-30 13:33:42 +00:00
items: [
[
{
2023-11-08 18:16:31 +00:00
label: 'Router',
items: [
{ label: 'Theming', route: '/theming' },
{ label: 'Unstyled', route: '/unstyled' }
]
2023-08-30 13:33:42 +00:00
}
],
[
{
2023-11-08 18:16:31 +00:00
label: 'Programmatic',
items: [
{
label: 'Installation',
command: () => {
2023-12-26 18:38:03 +00:00
this.$router.push('/introduction');
2023-11-08 18:16:31 +00:00
}
}
]
2023-08-30 13:33:42 +00:00
}
],
[
{
2023-11-08 18:16:31 +00:00
label: 'External',
items: [
{
label: 'Vue.js',
url: 'https://vuejs.org/'
},
{
label: 'Vite.js',
url: 'https://vuejs.org/'
}
]
2023-08-30 13:33:42 +00:00
}
]
]
}
]
};
}
};
2023-10-15 09:38:39 +00:00
<\/script>
`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2023-08-30 13:33:42 +00:00
<div class="card">
<MegaMenu :model="items">
2023-11-08 18:16:31 +00:00
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple :href="href" @click="navigate">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-30 13:33:42 +00:00
</a>
</router-link>
2023-11-08 18:16:31 +00:00
<a v-else v-ripple :href="item.url" :target="item.target">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-30 13:33:42 +00:00
</a>
</template>
</MegaMenu>
</div>
</template>
<script setup>
import { ref } from "vue";
2024-02-13 10:43:23 +00:00
import { useRouter } from 'vue-router';
2023-11-08 18:16:31 +00:00
const router = useRouter();
2023-08-30 13:33:42 +00:00
const items = ref([
{
2023-11-08 18:16:31 +00:00
label: 'Navigation',
icon: 'pi pi-link',
2023-08-30 13:33:42 +00:00
items: [
[
{
2023-11-08 18:16:31 +00:00
label: 'Router',
items: [
{ label: 'Theming', route: '/theming' },
{ label: 'Unstyled', route: '/unstyled' }
]
2023-08-30 13:33:42 +00:00
}
],
[
{
2023-11-08 18:16:31 +00:00
label: 'Programmatic',
items: [
{
label: 'Installation',
command: () => {
2024-02-13 10:43:23 +00:00
router.push('/introduction');
2023-11-08 18:16:31 +00:00
}
}
]
2023-08-30 13:33:42 +00:00
}
],
[
{
2023-11-08 18:16:31 +00:00
label: 'External',
items: [
{
label: 'Vue.js',
url: 'https://vuejs.org/'
},
{
label: 'Vite.js',
url: 'https://vuejs.org/'
}
]
2023-08-30 13:33:42 +00:00
}
]
]
}
]);
2023-10-15 09:38:39 +00:00
<\/script>
`
2023-08-30 13:33:42 +00:00
}
};
}
};
</script>