primevue-mirror/doc/tieredmenu/RouterDoc.vue

222 lines
7.1 KiB
Vue
Raw Normal View History

2023-08-30 13:33:42 +00:00
<template>
<DocSectionText v-bind="$attrs">
2023-11-06 15:14:05 +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>
<div class="card flex justify-content-center">
<TieredMenu :model="items">
2023-11-06 15:14:05 +00:00
<template #item="{ item, props, hasSubmenu }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple :href="href" v-bind="props.action" @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-06 15:14:05 +00:00
<a v-else v-ripple :href="item.url" :target="item.target" v-bind="props.action">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-11-07 14:22:54 +00:00
<span v-if="hasSubmenu" class="pi pi-angle-right ml-auto" />
2023-08-30 13:33:42 +00:00
</a>
</template>
</TieredMenu>
</div>
2023-11-06 15:14:05 +00:00
<DocSectionCode :code="code" hideStackBlitz hideCodeSandbox />
2023-08-30 13:33:42 +00:00
</template>
<script>
export default {
data() {
return {
items: [
{
2023-11-06 15:14:05 +00:00
label: 'Router',
icon: 'pi pi-palette',
2023-08-30 13:33:42 +00:00
items: [
{
2023-11-06 15:14:05 +00:00
label: 'Styled',
route: '/theming'
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
label: 'Unstyled',
route: '/unstyled'
2023-08-30 13:33:42 +00:00
}
]
},
{
2023-11-06 15:14:05 +00:00
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
this.$router.push('/installation');
}
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
label: 'External',
icon: 'pi pi-home',
2023-08-30 13:33:42 +00:00
items: [
{
2023-11-06 15:14:05 +00:00
label: 'Vue.js',
url: 'https://vuejs.org/'
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
label: 'Vite.js',
url: 'https://vuejs.org/'
2023-08-30 13:33:42 +00:00
}
]
}
],
code: {
2023-09-22 12:54:14 +00:00
basic: `
2023-10-16 15:12:36 +00:00
<TieredMenu :model="items">
2023-11-06 15:14:05 +00:00
<template #item="{ item, props, hasSubmenu }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple :href="href" v-bind="props.action" @click="navigate">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-10-16 15:12:36 +00:00
</a>
</router-link>
2023-11-06 15:14:05 +00:00
<a v-else v-ripple :href="item.url" :target="item.target" v-bind="props.action">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-11-07 14:22:54 +00:00
<span v-if="hasSubmenu" class="pi pi-angle-right ml-auto" />
2023-10-16 15:12:36 +00:00
</a>
</template>
</TieredMenu>
2023-10-15 09:38:39 +00:00
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-08-30 13:33:42 +00:00
<div class="card flex justify-content-center">
2023-10-16 15:12:36 +00:00
<TieredMenu :model="items">
2023-11-06 15:14:05 +00:00
<template #item="{ item, props, hasSubmenu }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple :href="href" v-bind="props.action" @click="navigate">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-10-16 15:12:36 +00:00
</a>
</router-link>
2023-11-06 15:14:05 +00:00
<a v-else v-ripple :href="item.url" :target="item.target" v-bind="props.action">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-11-07 14:22:54 +00:00
<span v-if="hasSubmenu" class="pi pi-angle-right ml-auto" />
2023-10-16 15:12:36 +00:00
</a>
</template>
</TieredMenu>
2023-08-30 13:33:42 +00:00
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
2023-11-06 15:14:05 +00:00
label: 'Router',
icon: 'pi pi-palette',
2023-08-30 13:33:42 +00:00
items: [
{
2023-11-06 15:14:05 +00:00
label: 'Styled',
route: '/theming'
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
label: 'Unstyled',
route: '/unstyled'
2023-08-30 13:33:42 +00:00
}
]
},
{
2023-11-06 15:14:05 +00:00
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
this.$router.push('/installation');
}
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
label: 'External',
icon: 'pi pi-home',
2023-08-30 13:33:42 +00:00
items: [
{
2023-11-06 15:14:05 +00:00
label: 'Vue.js',
url: 'https://vuejs.org/'
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
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 flex justify-content-center">
2023-10-16 15:12:36 +00:00
<TieredMenu :model="items">
2023-11-06 15:14:05 +00:00
<template #item="{ item, props, hasSubmenu }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple :href="href" v-bind="props.action" @click="navigate">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-10-16 15:12:36 +00:00
</a>
</router-link>
2023-11-06 15:14:05 +00:00
<a v-else v-ripple :href="item.url" :target="item.target" v-bind="props.action">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-11-07 14:22:54 +00:00
<span v-if="hasSubmenu" class="pi pi-angle-right ml-auto" />
2023-10-16 15:12:36 +00:00
</a>
</template>
</TieredMenu>
2023-08-30 13:33:42 +00:00
</div>
</template>
<script setup>
import { ref } from "vue";
2023-11-06 15:14:05 +00:00
import { useRouter } from "vue";
const router = useRouter();
2023-10-30 10:43:15 +00:00
2023-08-30 13:33:42 +00:00
const items = ref([
{
2023-11-06 15:14:05 +00:00
label: 'Router',
icon: 'pi pi-palette',
2023-08-30 13:33:42 +00:00
items: [
{
2023-11-06 15:14:05 +00:00
label: 'Styled',
route: '/theming'
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
label: 'Unstyled',
route: '/unstyled'
2023-08-30 13:33:42 +00:00
}
]
},
{
2023-11-06 15:14:05 +00:00
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
router.push('/installation');
}
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
label: 'External',
icon: 'pi pi-home',
2023-08-30 13:33:42 +00:00
items: [
{
2023-11-06 15:14:05 +00:00
label: 'Vue.js',
url: 'https://vuejs.org/'
2023-08-30 13:33:42 +00:00
},
{
2023-11-06 15:14:05 +00:00
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>