primevue-mirror/doc/menu/RouterDoc.vue

169 lines
5.4 KiB
Vue
Raw Normal View History

2023-08-29 12:50:04 +00:00
<template>
2023-08-30 07:26:11 +00:00
<DocSectionText v-bind="$attrs">
2023-11-04 08:20:02 +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 07:26:11 +00:00
</DocSectionText>
2023-08-29 12:50:04 +00:00
<div class="card flex justify-content-center">
<Menu :model="items">
2023-11-04 08:20:02 +00:00
<template #item="{ item, props }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
2023-11-04 09:33:47 +00:00
<a v-ripple :href="href" v-bind="props.action" @click="navigate">
2023-11-04 08:20:02 +00:00
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-29 12:50:04 +00:00
</a>
</router-link>
2023-11-04 08:20:02 +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-08-29 12:50:04 +00:00
</a>
</template>
</Menu>
</div>
2024-01-30 08:16:35 +00:00
<DocSectionCode :code="code" hideStackBlitz />
2023-08-29 12:50:04 +00:00
</template>
<script>
export default {
data() {
return {
items: [
{
2023-11-04 08:20:02 +00:00
label: 'Navigate',
2023-08-29 12:50:04 +00:00
items: [
{
2023-11-04 08:20:02 +00:00
label: 'Router Link',
icon: 'pi pi-palette',
route: '/unstyled'
2023-08-29 12:50:04 +00:00
},
{
2023-11-04 08:20:02 +00:00
label: 'Programmatic',
icon: 'pi pi-link',
2023-08-29 12:50:04 +00:00
command: () => {
2023-12-26 18:38:03 +00:00
this.$router.push('/introduction');
2023-08-29 12:50:04 +00:00
}
},
{
2023-11-04 08:20:02 +00:00
label: 'External',
2023-11-04 08:33:21 +00:00
icon: 'pi pi-home',
2023-11-04 08:20:02 +00:00
url: 'https://vuejs.org/'
2023-08-29 12:50:04 +00:00
}
]
}
],
code: {
2023-09-22 12:54:14 +00:00
basic: `
<Menu :model="items">
2023-11-04 08:20:02 +00:00
<template #item="{ item, props }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
2023-11-04 09:33:47 +00:00
<a v-ripple :href="href" v-bind="props.action" @click="navigate">
2023-11-04 08:20:02 +00:00
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-29 12:50:04 +00:00
</a>
</router-link>
2023-11-04 08:20:02 +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-08-29 12:50:04 +00:00
</a>
</template>
2023-10-15 09:38:39 +00:00
</Menu>
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-08-29 12:50:04 +00:00
<div class="card flex justify-content-center">
<Menu :model="items">
2023-11-04 08:20:02 +00:00
<template #item="{ item, props }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
2023-11-04 09:33:47 +00:00
<a v-ripple :href="href" v-bind="props.action" @click="navigate">
2023-11-04 08:20:02 +00:00
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-29 12:50:04 +00:00
</a>
</router-link>
2023-11-04 08:20:02 +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-08-29 12:50:04 +00:00
</a>
</template>
</Menu>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
2023-11-04 08:20:02 +00:00
label: 'Router Link',
icon: 'pi pi-palette',
route: '/unstyled'
2023-08-29 12:50:04 +00:00
},
{
2023-11-04 08:20:02 +00:00
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
2023-12-26 18:38:03 +00:00
this.$router.push('/introduction');
2023-11-04 08:20:02 +00:00
}
},
{
label: 'External',
2023-11-04 08:33:21 +00:00
icon: 'pi pi-home',
2023-11-04 08:20:02 +00:00
url: 'https://vuejs.org/'
2023-08-29 12:50:04 +00:00
}
]
};
}
};
2023-10-15 09:38:39 +00:00
<\/script>
`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2023-08-29 12:50:04 +00:00
<div class="card flex justify-content-center">
<Menu :model="items">
2023-11-04 08:20:02 +00:00
<template #item="{ item, props }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
2023-11-04 09:33:47 +00:00
<a v-ripple :href="href" v-bind="props.action" @click="navigate">
2023-11-04 08:20:02 +00:00
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
2023-08-29 12:50:04 +00:00
</a>
</router-link>
2023-11-04 08:20:02 +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-08-29 12:50:04 +00:00
</a>
</template>
</Menu>
</div>
</template>
<script setup>
import { ref } from "vue";
2023-11-04 08:20:02 +00:00
import { useRouter } from "vue";
const router = useRouter();
2023-08-29 12:50:04 +00:00
2023-10-04 09:45:35 +00:00
const items = ref([
2023-08-29 12:50:04 +00:00
{
2023-11-04 08:20:02 +00:00
label: 'Router Link',
icon: 'pi pi-palette',
route: '/unstyled'
2023-08-29 12:50:04 +00:00
},
{
2023-11-04 08:20:02 +00:00
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
2023-12-26 18:38:03 +00:00
this.$router.push('/introduction');
2023-11-04 08:20:02 +00:00
}
},
{
label: 'External',
2023-11-04 08:33:21 +00:00
icon: 'pi pi-home',
2023-11-04 08:20:02 +00:00
url: 'https://vuejs.org/'
2023-08-29 12:50:04 +00:00
}
]);
2023-10-15 09:38:39 +00:00
<\/script>
`
2023-08-29 12:50:04 +00:00
}
};
}
};
</script>