DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Vue Context Menu - Templates

The ContextMenu component provides full control over the appearance and behavior of menu items across all nesting levels.

Backend API
<template> <div> <div class="label"> Right click an image to display the context menu: </div> <img id="image" alt="product" :src="'../../../../images/products/5.png'" > <DxContextMenu :data-source="items" :width="200" target="#image" @item-click="itemClick" > <template #item="{ data: e }"> <div class="item-template-container"> <span v-if="e.icon" :class="['dx-icon', e.icon]" /> <span class="dx-menu-item-text">{{ e.text }}</span> <span v-if="e.items" class="dx-icon-spinright dx-icon" /> </div> </template> </DxContextMenu> </div> </template> <script setup lang="ts"> import { DxContextMenu, type DxContextMenuTypes } from 'devextreme-vue/context-menu'; import notify from 'devextreme/ui/notify'; import { contextMenuItems as items } from './data.ts'; import type { ContextMenuItem } from './types'; function itemClick({ itemData }: DxContextMenuTypes.ItemClickEvent<ContextMenuItem>) { if (itemData && !itemData.items) { notify(`The "${itemData.text}" item was clicked`, 'success', 1500); } } </script> <style> .item-template-container { display: flex; align-items: center; gap: 6px; width: 100%; } .dx-menu-item-text { flex-grow: 1; } #image { height: 300px; } .label { color: var(--dx-texteditor-color-label); } </style>
import type { ContextMenuItem } from './types'; export const contextMenuItems: ContextMenuItem[] = [ { text: 'Share', icon: 'dx-icon-globe', items: [ { text: 'Facebook' }, { text: 'Twitter' }], }, { text: 'Download', icon: 'dx-icon-download' }, { text: 'Add Comment', icon: 'dx-icon-add' }, { text: 'Add to Favorite', icon: 'dx-icon-favorites' }, ];
import { createApp } from 'vue'; import App from './App.vue'; createApp(App).mount('#app');
export interface ContextMenuItem { text: string; icon?: string; items?: ContextMenuItem[]; }
<!DOCTYPE html> <html lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="./bundle.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"> </div> </div> <script src="bundles/vendor/vue.vendor.js"></script> <script src="./bundle.js"></script> </body> </html>