A Guide To Enhance UI with Vue.js and Drag-and-drop

Ömer Faruk Olcay
Insider Engineering
6 min readJul 10, 2023

An organized interface design is one of the most important steps in improving the user experience.

User dashboards, which are interfaces that allow users to manage multiple functions, offer a customizable experience to users.

Using the Vue.js framework to create a drag-and-drop feature in a user dashboard gives users a more flexible experience. We will learn the concept of user flexibility, the importance of user flexibility with the drag-and-drop feature, how to develop it with Vue.js, and the benefits users can gain from this feature.

What is the Drag & Drop Feature?

The drag-and-drop feature allows users to easily rearrange and resize dashboard widgets by dragging and dropping them. This feature enables them to personalize their dashboard.

Users can use this to create a personalized layout that is tailored to their workflow. They might want to manage multiple widgets and customize them according to their needs. For example, if a user has a widget that they frequently use in their daily workflow, they can easily move it to the top of their dashboard for easy access. Creating dashboards with a JavaScript framework like Vue.js simplifies the process.

In this article, I will inform you about, the flexibility that dashboards offer users, and the impact of the drag-and-drop feature on users. You will also learn the steps required to create a drag-and-drop feature using Vue.js.

Let’s create a layout from scratch

  • You will need to install the vue-grid-layout library using either npm or yarn.
npm install vue-grid-layout
or
yarn add vue-grid-layout
  • To use the Vue-grid-layout library, you need to create a Vue.js project. You can use the Vue CLI to create a Vue.js project. The Vue CLI is a tool that helps you create, develop, and deploy a Vue.js project.
npm install -g vue-cli
vue init webpack my-project
cd my-project
npm install
npm run dev
<grid-layout :layout="layout">
<grid-item
v-for="item in layout"
:key="item.i"
:x="item.x"
:y="item.y"
:w="item.w"
:h="item.h"
:i="item.i">
<span class="text">{{ item.i }}</span>
</grid-item>
</grid-layout>
  • In the GridLayout component, “layout” is the definition of an element placement object, where we can use the x-axis and y-axis to define each item’s position.
  • In the GridItem component, “x” and “y” are axes, and “w” and “h” represent the width and height of each item. Lastly, i is the identifier index of each element.
  • Now, we can import the library in the script section as follows:
import VueGridLayout from 'vue-grid-layout';

const { GridLayout, GridItem } = VueGridLayout;
  • After importing, we can define the components and a dummy layout
export default {
components: {
GridLayout,
GridItem,
},
data() {
return {
layout: [
{ i: "FIRST", x: 0, y: 0, w: 2, h: 10 },
{ i: "MIDDLE", x: 2, y: 1, w: 2, h: 10 },
{ i: "LAST", x: 4, y: 2, w: 2, h: 10 },
],
};
},
};
  • By adding style to the grid items, you can make the layout more visible
<style lang="scss" scoped>
.vue-grid-item:not(.vue-grid-placeholder) {
background: #defdef;
border: 1px solid black;
}
.vue-grid-item .text {
font-size: 24px;
text-align: center;
position: absolute;
margin: auto;
height: 100%;
width: 100%;
}
</style>

The example layout will look like the below:

The output of the layout using simple boxes as resizable elements

You can easily use the drag-and-drop feature by changing positions, even resizing them with the icon that appears at the bottom right side.

Placeholder visual of the layout elements after resizing and dragging to a new place
  • When we combine all our writings in one place, we have a code block like the one below:
<template>
<grid-layout :layout="layout">
<grid-item
v-for="item in layout"
:key="item.i"
:x="item.x"
:y="item.y"
:w="item.w"
:h="item.h"
:i="item.i">
<span class="text">{{item.i}}</span>
</grid-item>
</grid-layout>
</template>
<script>
import VueGridLayout from 'vue-grid-layout';

const { GridLayout, GridItem } = VueGridLayout;

export default {
components: {
GridLayout,
GridItem
},
data () {
return {
layout: [
{ i: 'FIRST', x: 0, y: 0, w: 2, h: 10 },
{ i: 'MIDDLE', x: 2, y: 1, w: 2, h: 10 },
{ i: 'LAST', x: 4, y: 2, w: 2, h: 10 }
]
};
}
};
</script>
<style lang="scss" scoped>
.vue-grid-item:not(.vue-grid-placeholder) {
background: #defdef;
border: 1px solid black;
}
.vue-grid-item .text {
font-size: 24px;
text-align: center;
position: absolute;
margin: auto;
height: 100%;
width: 100%;
}
</style>
  • As you can see in the example, there are only texts among the elements we mean as grid items, but you can define your widgets in the “grid-item” and define drag-and-drop properties for them.

You can imagine a layout like below design:

An alternative design for a layout that includes flexibility to replace widgets

Benefits of using the Drag-and-Drop Feature in a User Dashboard

Users benefit greatly from the drag-and-drop feature in user dashboards.

Efficiency & Flexibility

The dashboard, which has a drag-and-drop feature where users can be more engaged with the created dashboard and can customize the appearance of the dashboard, not only increases the speed of users accessing metrics and the time they spend on the page but also increases the time they are in the dashboard. In addition to being able to prioritize widgets such as sorting according to their own usage habits, it allows them to directly access the information or widgets they are looking for without having to dominate all the content on the page for comprehensive dashboards.

Increased Collaboration

Users can share their layouts by communicating with other users, thus contributing to the development of the dashboard by optimizing the workflow. As Insider, we obtained approximately a 20% increase in the engagement of the users of our dashboard right after launching the drag-and-drop feature. Overall, dashboards with drag-and-drop have numerous advantages and allow users to significantly simplify their lives. With the help of Vue.js and the library developed in it, you can give your users this experience.

User-Friendly Experience

A user-friendly experience is provided by the drag-and-drop feature in a user dashboard. Users can easily customize their dashboard by dragging and dropping widgets. This feature can help users feel more in control of the application and increase their satisfaction with it.

Summary

In this article, we discussed the drag-and-drop feature in a user dashboard and how it provides users with flexibility and efficiency. We also looked at how Vue.js can be used to create a drag-and-drop feature in a user dashboard.

You can easily create customizable and user-friendly dashboards with Vue.js that allow users to rearrange and resize layouts of their dashboards to fit their workflow. You can easily add drag-and-drop functionality to your dashboard using the vue-grid-layout library. The drag-and-drop feature in a user dashboard improves flexibility, efficiency, user-friendliness, and collaboration. You can increase user satisfaction and productivity by providing a more flexible and efficient user interface.

Finally, using Vue.js to create a drag-and-drop feature in a user dashboard is a simple and effective way to provide your users with a personalized and streamlined user interface.

Thank you for your time, open to your comments and suggestions in the comments section, and feel free to contact me via LinkedIn.

If you enjoyed this article, check out our Insider Engineering Blog to find more:

--

--