primevue-mirror/doc/panelmenu/RouterDoc.vue

234 lines
8.1 KiB
Vue
Raw Normal View History

2023-08-30 13:33:42 +00:00
<template>
<DocSectionText v-bind="$attrs">
2023-11-08 08:33:18 +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>
2023-11-08 08:33:18 +00:00
<div class="card flex justify-content-center">
<PanelMenu :model="items" class="w-full md:w-20rem">
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple class="flex align-items-center cursor-pointer text-color px-3 py-2" :href="href" @click="navigate">
<span :class="item.icon" />
<span class="ml-2 text-color">{{ item.label }}</span>
</a>
</router-link>
<a v-else v-ripple class="flex align-items-center cursor-pointer text-color px-3 py-2" :href="item.url" :target="item.target">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
<span v-if="item.items" class="pi pi-angle-down text-primary ml-auto" />
</a>
</template>
</PanelMenu>
</div>
2024-01-30 08:16:35 +00:00
<DocSectionCode :code="code" hideStackBlitz />
2023-08-30 13:33:42 +00:00
</template>
2023-11-08 08:33:18 +00:00
<script>
export default {
data() {
return {
items: [
{
label: 'Router',
icon: 'pi pi-palette',
items: [
{
label: 'Styled',
icon: 'pi pi-eraser',
route: '/theming'
},
{
label: 'Unstyled',
icon: 'pi pi-heart',
2024-05-02 10:42:38 +00:00
route: '/theming/unstyled'
2023-11-08 08:33:18 +00:00
}
]
},
{
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
2023-12-26 18:38:03 +00:00
this.$router.push('/introduction');
2023-11-08 08:33:18 +00:00
}
},
{
label: 'External',
icon: 'pi pi-home',
items: [
{
label: 'Vue.js',
icon: 'pi pi-star',
url: 'https://vuejs.org/'
},
{
label: 'Vite.js',
icon: 'pi pi-bookmark',
url: 'https://vuejs.org/'
}
]
}
],
code: {
basic: `
<PanelMenu :model="items">
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple class="flex align-items-center cursor-pointer text-color px-3 py-2" :href="href" @click="navigate">
<span :class="item.icon" />
<span class="ml-2 text-color">{{ item.label }}</span>
</a>
</router-link>
<a v-else v-ripple class="flex align-items-center cursor-pointer text-color px-3 py-2" :href="item.url" :target="item.target">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
<span v-if="item.items" class="pi pi-angle-down text-primary ml-auto" />
</a>
</template>
</PanelMenu>
`,
options: `
<template>
<div class="card flex justify-content-center">
<PanelMenu :model="items" class="w-full md:w-20rem">
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple class="flex align-items-center cursor-pointer text-color px-3 py-2" :href="href" @click="navigate">
<span :class="item.icon" />
<span class="ml-2 text-color">{{ item.label }}</span>
</a>
</router-link>
<a v-else v-ripple class="flex align-items-center cursor-pointer text-color px-3 py-2" :href="item.url" :target="item.target">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
<span v-if="item.items" class="pi pi-angle-down text-primary ml-auto" />
</a>
</template>
</PanelMenu>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
label: 'Router',
icon: 'pi pi-palette',
items: [
{
label: 'Styled',
icon: 'pi pi-eraser',
route: '/theming'
},
{
label: 'Unstyled',
icon: 'pi pi-heart',
2024-05-02 10:42:38 +00:00
route: '/theming/unstyled'
2023-11-08 08:33:18 +00:00
}
]
},
{
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
2023-12-26 18:38:03 +00:00
this.$router.push('/introduction');
2023-11-08 08:33:18 +00:00
}
},
{
label: 'External',
icon: 'pi pi-home',
items: [
{
label: 'Vue.js',
icon: 'pi pi-star',
url: 'https://vuejs.org/'
},
{
label: 'Vite.js',
icon: 'pi pi-bookmark',
url: 'https://vuejs.org/'
}
]
}
]
};
}
};
<\/script>
`,
composition: `
<template>
<div class="card flex justify-content-center">
<PanelMenu :model="items" class="w-full md:w-20rem">
<template #item="{ item }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple class="flex align-items-center cursor-pointer text-color px-3 py-2" :href="href" @click="navigate">
<span :class="item.icon" />
<span class="ml-2 text-color">{{ item.label }}</span>
</a>
</router-link>
<a v-else v-ripple class="flex align-items-center cursor-pointer text-color px-3 py-2" :href="item.url" :target="item.target">
<span :class="item.icon" />
<span class="ml-2">{{ item.label }}</span>
<span v-if="item.items" class="pi pi-angle-down text-primary ml-auto" />
</a>
</template>
</PanelMenu>
</div>
</template>
<script setup>
import { ref } from "vue";
2024-02-13 10:43:23 +00:00
import { useRouter } from 'vue-router';
2023-11-08 08:33:18 +00:00
const router = useRouter();
const items = ref([
{
label: 'Router',
icon: 'pi pi-palette',
items: [
{
label: 'Styled',
icon: 'pi pi-eraser',
route: '/theming'
},
{
label: 'Unstyled',
icon: 'pi pi-heart',
2024-05-02 10:42:38 +00:00
route: '/theming/unstyled'
2023-11-08 08:33:18 +00:00
}
]
},
{
label: 'Programmatic',
icon: 'pi pi-link',
command: () => {
2023-12-26 18:38:03 +00:00
router.push('/introduction');
2023-11-08 08:33:18 +00:00
}
},
{
label: 'External',
icon: 'pi pi-home',
items: [
{
label: 'Vue.js',
icon: 'pi pi-star',
url: 'https://vuejs.org/'
},
{
label: 'Vite.js',
icon: 'pi pi-bookmark',
url: 'https://vuejs.org/'
}
]
}
]);
<\/script>
`
}
};
}
};
</script>