vue draw mdi icon

Vue: Draw MDI Icons with Ease

By Joseph Davis
AD

Are you a developer looking to integrate Material Design Icons (MDI) into your Vue.js project? Vue.js, being a progressive JavaScript framework, has an abundance of plugins and libraries that can simplify complex tasks like integrating icons. One such plugin is mdi-vue, which allows you to use MDI icons in your Vue application with ease. In this article, we'll guide you through the process of drawing MDI icons using the mdi-vue plugin in Vue.js.

Before we dive in, ensure you have Vue CLI installed globally. If not, you can install it using npm (Node Package Manager) with the following command: `npm install -g @vue/cli`.

Setting Up the Vue Project and mdi-vue

First, let's set up a new Vue project and install the mdi-vue plugin.

AD
VERITY NO GET BACK INSIDE-
VERITY NO GET BACK INSIDE-
a painting of a woman holding a bird in her hands and flowers around her neck
a painting of a woman holding a bird in her hands and flowers around her neck
an animated character with black hair and glasses
an animated character with black hair and glasses

Initialize a new Vue project using Vue CLI: `vue create vue-mdi-icon-project`. Then, navigate to your project folder: `cd vue-mdi-icon-project`.

Installing mdi-vue Plugin

Install the mdi-vue plugin using npm: `npm install mdi-vue`. Alternatively, you can use Yarn: `yarn add mdi-vue`.

«« ៸៸ ׂ.𝒱. ꧦ 𑁯ᰍ. .
«« ៸៸ ׂ.𝒱. ꧦ 𑁯ᰍ. .
a drawing of a white cartoon character with black eyes
a drawing of a white cartoon character with black eyes
Go Bok-su Married in Red
Go Bok-su Married in Red

Make sure to import the plugin in your main.js file: `import 'mdi-vue/lib/style.css'; import Vue from 'vue'; importMdikatab from 'mdi-vue'; Vue.use(MdiPlugin); new Vue({ render: h => h(App) }).$mount('#app')`.

Using MDI Icons in Vue Components

Now that our project is set up and the mdi-vue plugin is installed, let's learn how to use MDI icons in our Vue components.

AD

MDI icons can be used in the component's template like regular HTML tags, with the icon name as the tag name. For example, to use the heart icon, you would write ``.

Margo
Margo
SDV Edit pict Md
SDV Edit pict Md
an image of two eyes with one being drawn
an image of two eyes with one being drawn
view point
view point
Another Misaki Mei, Another Misaki, Emo Princess, Cybergoth Anime, Cidade Do México, Anime Black Hair, Anime Sisters, Animated Wallpapers For Mobile, Another Anime
Another Misaki Mei, Another Misaki, Emo Princess, Cybergoth Anime, Cidade Do México, Anime Black Hair, Anime Sisters, Animated Wallpapers For Mobile, Another Anime
a woman with blue hair and green eyes covers her face as she holds her hand to her mouth
a woman with blue hair and green eyes covers her face as she holds her hand to her mouth

Passing Props to MDI Icons

You can pass props to MDI icons just like you would with a regular component. For example, to change the size of the heart icon, you would write ``.

To see the list of available props, check out the official mdi-vue documentation.

AD

Using MDI Icons in Vuex Store

MDI icons can also be used in Vuex store. You can create actions and mutations that dispatch icons, updating the Vuex store's state. Here's an example:

averythemayo pfp
averythemayo pfp
a drawing of a man with black hair and a red mask on it's face
a drawing of a man with black hair and a red mask on it's face
V maid Edit pict Md
V maid Edit pict Md
ALIEN
ALIEN
Omdt ୨ৎ …
Omdt ୨ৎ …
♪‧₊˚
♪‧₊˚
an image of a cartoon character wearing a blue suit
an image of a cartoon character wearing a blue suit
a pencil drawing of a girl with long hair and big eyes, wearing a dress
a pencil drawing of a girl with long hair and big eyes, wearing a dress
Invincible
Invincible
Tracksuit Mark
Tracksuit Mark
🫰🏼🫶🏻
🫰🏼🫶🏻
a drawing of a cat with green eyes
a drawing of a cat with green eyes
a black and white drawing of a city by the ocean
a black and white drawing of a city by the ocean
```javascript actions: { toggleLike({ commit, state }, item) { const index = state.items.findIndex(i => i.id === item.id); if (index !== -1) { state.items[index].liked = !state.items[index].liked; commit('UPDATE_ITEM', state.items[index]); } }, }, mutations: { UPDATE_ITEM(state, item) { state.items = [...state.items]; }, }, ```

The 'toggleLike' action above toggles the 'liked' status of an item, and the 'UPDATE_ITEM' mutation updates the item in the Vuex store's 'items' array. You can use the 'liked' status to conditionally render an MDI icon, for example, `` and ``.

Iterate through the items in your Vuex store using the 'v-for' directive, and conditionally render the appropriate MDI icon based on the 'liked' status of each item. For instance,

AD
```javascript ```

This way, clicking on the icon will toggle its fill status and update the Vuex store's state accordingly.

Advanced Usage: Icon Sets and Themes

MDI icons come in various sets (solid, outline, round, etc.) and themes (light, dark). You can specify these when using the icon in your template.

To use an outline version of the heart icon, you would write ``. To use the icon in the dark theme, you would write ``.

Customizing Icon Colors

By default, MDI icons are styled using CSS classes. However, you can also use the ':style' binding to customize the color of an icon. For example, to change the color of the heart icon to red, you would write ``.

You can also use the '$vuetify' global style variable to set the color. For instance, `` will set the color of the heart icon to the secondary color defined in your vuetify theme.

And there you have it! You've now learned how to draw MDI icons in your Vue.js project using the mdi-vue plugin. With this knowledge, you can easily integrate Material Design Icons into your Vue applications, enhancing their user interface and interactivity. Happy coding!

AD